package cn.fl.project.service.impl;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.constant.SysUlFilesRecConstant;
import cmm.comm.facade.upload.dto.SysUlFilesRecDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.dto.MessageDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.dto.SysOrgDTO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.capital.condition.CapFeeOutLogQueryCondition;
import cn.fl.capital.condition.CapPayInfoQueryCondition;
import cn.fl.capital.constant.CapPayInfoConstant;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.capital.constant.SettleConstant;
import cn.fl.capital.dto.CapPayInfoDTO;
import cn.fl.capital.service.ICapFeeOutLogService;
import cn.fl.capital.service.ICapPayInfoApiService;
import cn.fl.capital.vo.CapFeeOutLogVO;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.ProjectUtils;
import cn.fl.project.api.IPrjSettleOfFinaInstApiService;
import cn.fl.project.condition.*;
import cn.fl.project.constant.*;
import cn.fl.project.dto.PrjBscInfoDTO;
import cn.fl.project.dto.PrjCstBscInfoDTO;
import cn.fl.project.dto.PrjPrdPaySchMDTO;
import cn.fl.project.service.*;
import cn.fl.project.transform.PrjMfrPrdPaySchMVOTransform;
import cn.fl.project.transform.PrjPrdPaySchMVOTransform;
import cn.fl.project.transform.PrjPrdPaySchTagVOTransform;
import cn.fl.project.transform.PrjQuatPrpsPaySchVOTransform;
import cn.fl.project.vo.*;
import cn.fl.settlement.service.ISettlementFileService;
import cn.fl.spl.utils.FileUtil;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.transform.SysDictionaryVOTransform;
import cn.fl.system.transform.SysUlFilesRecVOTransform;
import cn.fl.system.vo.SysDictionaryVO;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.lb.framework.poi.pdf.export.PdfExportServer;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import fl.customer.facade.customer.api.ICustomerApiService;
import fl.customer.facade.customer.dto.CstBscInfoDTO;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.tjbank.facade.api.ITjBankApi;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.Region;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;
import java.util.*;
/**
 * @Description: 项目产品支付表主信息表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class PrjPrdPaySchMServiceImpl implements IPrjPrdPaySchMService {

	/**
	 * 日志
	 */
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(PrjPrdPaySchMServiceImpl.class);

	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IPrjPrdPaySchTagApiService prjPrdPaySchTagApiService;
	@Autowired
	private IPrjPrdPaySchMApiService prjPrdPaySchMApiService;
	@Autowired
	private IPrjPrdBscInfoService prjPrdBscInfoService;
	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	@Autowired
	private IPrjQuatPrpsService prjQuatPrpsService;
	@Autowired
	private IPrjQuatPrpsFeeService prjQuatPrpsFeeService;
	@Autowired
	private IPrjQuatPrpsPaySchService prjQuatPrpsPaySchService;
	@Autowired
	private ICstBscInfoService  cstBscInfoService;
	@Autowired
	private ISysDictionaryApiService  sysDictionaryApiService;

	@Autowired
	private ICapFeeOutLogService  capFeeOutLogService;//逾期信息

	@Autowired
	private IPrjPrdPaySchDService  prjPrdPaySchDService;//
	@Autowired
	private IPrjPrdPaySchTDService  prjPrdPaySchTDService;//

	@Autowired
	private IPrjPrdPaySchTMApiService prjPrdPaySchTMApiService;

	@Autowired
	private ISysOrgApiService sysOrgApiService;// 组织机构

	@Autowired
	private ICapPayInfoApiService capPayInfoApiService;

	@Autowired
	private IProjectApiService projectApiService;

	@Autowired
	private ICustomerApiService customerApiService;

	@Autowired
	private IPrjCstBscInfoService prjCstBscInfoService;

	@Autowired
	private IPrjCstAccInfoService prjCstAccInfoService;

	@Autowired
	private IUploadApiService uploadApiService;

	@Autowired
	private ITjBankApi tjBankApi;

	@Autowired
	private IPrjSettleOfFinaInstApiService prjSettleOfFinaInstApiService;

	@Autowired
	private ISettlementFileService settlementFileService;

	@Override
	public PrjPrdPaySchMVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)) return null;
		PrjPrdPaySchMDTO dto = this.prjPrdPaySchMApiService.selectPrjPrdPaySchMById(id);
		return PrjPrdPaySchMVOTransform.toVO(dto);
	}

	@Override
	public List<PrjPrdPaySchMDTO> searchTheSamePrdOtherPaySchMList(Long paySchId) throws BaseException {
		return prjPrdPaySchMApiService.searchTheSamePrdOtherPaySchMList(paySchId);
	}

	@Override
	public Long add(PrjPrdPaySchMVO entity) throws BaseException{
		if(null == entity) return null;
		//新能源、机构只修改费用项信息，不重新测算
		PrjBscInfoVO bscInfoVO = 	this.prjBscInfoService.selectById(entity.getPrjId());
		if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY)||StringUtils.isNotBlank(bscInfoVO.getInsCode())){
			return this.prjPrdPaySchMApiService.modifyPrjPrdPaySchMFeeList(PrjPrdPaySchMVOTransform.toDTO(entity), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		}else{
			PrjPrdPaySchMDTO prjPrdPay = prjPrdPaySchMApiService.prjQuatPrpsCalculate(PrjPrdPaySchMVOTransform.toDTO(entity), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			return this.prjPrdPaySchMApiService.addPrjPrdPaySchM(prjPrdPay);
		}
	}

	@Override
	public boolean removeByIds(List<Long> ids) throws BaseException{
		if(CollectionUtils.isEmpty(ids)) return false;
		return this.prjPrdPaySchMApiService.removePrjPrdPaySchMByIds(ids, CurrentThreadContext.getCurrentUserId());
	}

	@Override
	public boolean modify(PrjPrdPaySchMVO entity) throws BaseException{
		if(null == entity) return false;
		boolean flag = false;
		//新能源、机构只修改费用项信息，不重新测算
		PrjBscInfoVO bscInfoVO = 	this.prjBscInfoService.selectById(entity.getPrjId());
		PrjPrdBscInfoQueryCondition prjPrdBscInfoQueryCondition = new PrjPrdBscInfoQueryCondition();
		prjPrdBscInfoQueryCondition.setPrjId(entity.getPrjId());
		List<PrjPrdBscInfoVO> prjPrdBscInfoVOS = this.prjPrdBscInfoService.searchList(prjPrdBscInfoQueryCondition);
		boolean special = false;
		if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOS)){
			special = PrjMfrPrdPaySchMConstant.SPECIAL_MFR_NM_01.equals(prjPrdBscInfoVOS.get(0).getSplMfrNm()) || PrjMfrPrdPaySchMConstant.SPECIAL_MFR_NM_02.equals(prjPrdBscInfoVOS.get(0).getSplMfrNm());
		}
		if((bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY) || StringUtils.isNotBlank(bscInfoVO.getInsCode())) && !special){
			Long id =  this.prjPrdPaySchMApiService.modifyPrjPrdPaySchMFeeList(PrjPrdPaySchMVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),bscInfoVO.getCstMgrOrgCd());
			if(null!=id){
				flag =  true;
			}
		}else{
		PrjPrdPaySchMDTO prjPrdPay =  prjPrdPaySchMApiService.prjQuatPrpsCalculate(PrjPrdPaySchMVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),bscInfoVO.getCstMgrOrgCd());
			flag = this.prjPrdPaySchMApiService.modifyPrjPrdPaySchM(prjPrdPay);
		}
		//重卡厂商业务，重新生成厂商支付表信息
        /*if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)&&bscInfoVO.getIsSplMfr().intValue()==BaseConstant.IS_YESNO_YES){
            PrjPrdPaySchMDTO schMDTO = PrjPrdPaySchMVOTransform.toDTO(entity);
            schMDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
            schMDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            schMDTO.setFeeList(PrjPrdPaySchDVOTransform.toDTOList(entity.getPrjPrdPaySchDList()));
            this.prjPrdPaySchMApiService.modifyReGenMfrPrdPaySchM(schMDTO);
        }*/
		return flag;
	}

	@Override
	public boolean modifyLsDt(PrjPrdPaySchMVO entity) throws BaseException{
		if(null == entity) return false;
		PrjPrdPaySchMDTO prjPrdPay =  prjPrdPaySchMApiService.prjQuatPrpsCalculate(PrjPrdPaySchMVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		return this.prjPrdPaySchMApiService.modifyLsDt(prjPrdPay);
	}
	/*
     * 保存起租日（仅根据id保存单个值）
     */
	//@Override
	public void modifylsDt(Long ids, Date lsDts) throws BaseException{
		this.prjPrdPaySchMApiService.modifylsDt(ids,lsDts);
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page) page = new Pager();
		page = this.prjPrdPaySchMApiService.searchPrjPrdPaySchMListPage(page,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		page.setResultList(PrjPrdPaySchMVOTransform.toVOList((List<PrjPrdPaySchMDTO>)page.getResultList()));
		return page;
	}

	@Override
	public List<PrjPrdPaySchMVO> searchList(PrjPrdPaySchMQueryCondition condition) throws BaseException{
		 return PrjPrdPaySchMVOTransform.toVOList(this.prjPrdPaySchMApiService.searchPrjPrdPaySchMList(condition));
	}

	/**
	 * 根据客户经理查询项目产品信息
	 * @param condition
	 * @return
	 * @throws BaseException
	 */
	public List<PrjPrdPaySchMVO> selectPrjPrdList(PrjPrdPaySchMQueryCondition condition) throws BaseException{
		return PrjPrdPaySchMVOTransform.toVOList(this.prjPrdPaySchMApiService.selectPrjPrdList(condition));
	}

	@Override
	public PrjPrdPaySchMVO selectPrjPrdPaySchMAndDetailById(Long id) throws BaseException {
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"项目产品支付表id不能为空！");
		}
		PrjPrdPaySchMVO prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(this.prjPrdPaySchMApiService.selectPrjPrdPaySchMAndDetailById(id,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd()));
		getTotalValue(prjPrdPaySch);
		return prjPrdPaySch;
	}

    @Override
    public PrjPrdPaySchMVO selectPrjPrdPaySchMEnableAndDetailById(Long id) throws BaseException {
        if(StringUtils.isEmpty(id)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"项目产品支付表id不能为空！");
        }
        PrjPrdPaySchMVO prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(this.prjPrdPaySchMApiService.selectPrjPrdPaySchMEnableAndDetailById(id,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd()));
        getTotalValue(prjPrdPaySch);
        return prjPrdPaySch;
    }
    @Override
    public PrjMfrPrdPaySchMVO selectPrjMfrPrdPaySchMAndDetailById(Long id) throws BaseException {
        if(StringUtils.isEmpty(id)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"项目产品支付表id不能为空！");
        }
        PrjMfrPrdPaySchMVO prjPrdPaySch = PrjMfrPrdPaySchMVOTransform.toVO(this.prjPrdPaySchMApiService.selectPrjMfrPrdPaySchMAndDetailById(id,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd()));
        getMfrTotalValue(prjPrdPaySch);
        return prjPrdPaySch;
    }

	//计算首付款等信息
    private PrjMfrPrdPaySchMVO getMfrTotalValue(PrjMfrPrdPaySchMVO vo) {
        List<PrjPrdPaySchDVO> detailList = vo.getPayList();
        List<PrjPrdPrpsFeeDetailVO> prjPrdPayDetailList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
        List<PrjPrdPaySchDVO> feeList = new ArrayList<PrjPrdPaySchDVO>();
        List<PrjPrdPaySchDVO> feeDetailList = vo.getFeeList();
        //合计本金、合计利息、合计剩余本金、合计租金
        double  totalRntAmt = 0d;//合计租金
        double  totalPrinAmt = 0d;//合计本金
        double  totalIntAmt = 0d;//合计利息
        double totalRemPrinAmt = 0d;//合计剩余本金
        double firstPayAmt = 0d;//首付款
        Map<Integer,PrjPrdPrpsFeeDetailVO> prdPayMap = new HashMap<Integer,PrjPrdPrpsFeeDetailVO>();
        if(null!=vo){
            //计算首付款
            if(CollectionUtils.isNotEmpty(feeDetailList)){
                for (PrjPrdPaySchDVO fee : feeDetailList) {
                    //首付款
                    if(fee.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)){
                        firstPayAmt = DecimalUtils.add(firstPayAmt, fee.getFeeAmt());
                    }
                    fee.setFeeAmt(null==fee.getFeeAmt()?0:DecimalUtils.convertFenToYuan(Double.valueOf((fee.getFeeAmt())).longValue()));
                    feeList.add(fee);
                }
            }
            if(CollectionUtils.isNotEmpty(detailList)){
                for (PrjPrdPaySchDVO detail : detailList) {
                    if(!prdPayMap.containsKey(detail.getPayPd())){
                        PrjPrdPrpsFeeDetailVO feeDetail = new PrjPrdPrpsFeeDetailVO();
                        feeDetail.setPayPd(detail.getPayPd());
                        feeDetail.setIsModify(detail.getIsModify());
                        feeDetail.setPayDt(detail.getPayDt());
                        if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)){
                            //租金
                            totalRntAmt = DecimalUtils.add(totalRntAmt, detail.getFeeAmt());
                            feeDetail.setRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
                        }
                        if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)){
                            //	利息
                            totalIntAmt = DecimalUtils.add(totalIntAmt, detail.getFeeAmt());
                            feeDetail.setIntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
                        }
                        if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)){
                            //本金
                            totalPrinAmt = DecimalUtils.add(totalPrinAmt, detail.getFeeAmt());
                            feeDetail.setPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
                        }
                        if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_REMPRIN_PRICE)){
                            //剩余本金
                            totalRemPrinAmt = DecimalUtils.add(totalRemPrinAmt, detail.getFeeAmt());
                            feeDetail.setRemPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
                        }
                        prdPayMap.put(detail.getPayPd(), feeDetail);
                    }else{
                        if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)){
                            //租金
                            totalRntAmt = DecimalUtils.add(totalRntAmt, detail.getFeeAmt());
                            prdPayMap.get(detail.getPayPd()).setRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
                        }
                        if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)){
                            //	利息
                            totalIntAmt = DecimalUtils.add(totalIntAmt, detail.getFeeAmt());
                            prdPayMap.get(detail.getPayPd()).setIntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
                        }
                        if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)){
                            //本金
                            totalPrinAmt = DecimalUtils.add(totalPrinAmt, detail.getFeeAmt());
                            prdPayMap.get(detail.getPayPd()).setPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
                        }
                        if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_REMPRIN_PRICE)){
                            //剩余本金
                            totalRemPrinAmt = DecimalUtils.add(totalRemPrinAmt, detail.getFeeAmt());
                            prdPayMap.get(detail.getPayPd()).setRemPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
                        }
                    }

                }
            }
            for (Integer key : prdPayMap.keySet()) {
                prjPrdPayDetailList.add(prdPayMap.get(key));
            }

            sortPrjPrdPayList(prjPrdPayDetailList);
            vo.setPrjPrdPayDetailList(prjPrdPayDetailList);
            vo.setFeeList(feeList);
            vo.setActLsAmt(null==vo.getActLsAmt()?0:DecimalUtils.convertFenToYuan(Double.valueOf((vo.getActLsAmt())).longValue()));
            vo.setContAmt(null==vo.getContAmt()?0:DecimalUtils.convertFenToYuan(Double.valueOf((vo.getContAmt())).longValue()));
            vo.setEachEstRntAmt(null==vo.getEachEstRntAmt()?0:DecimalUtils.convertFenToYuan(Double.valueOf((vo.getEachEstRntAmt())).longValue()));
            vo.setTotLsItmAmt(null==vo.getTotLsItmAmt()?0:DecimalUtils.convertFenToYuan(Double.valueOf((vo.getTotLsItmAmt())).longValue()));
            vo.setTotalRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((totalRntAmt)).longValue()));
            vo.setTotalRemPrinAmt((DecimalUtils.convertFenToYuan(Double.valueOf((totalRemPrinAmt)).longValue())));
            vo.setTotalPrinAmt((DecimalUtils.convertFenToYuan(Double.valueOf((totalPrinAmt)).longValue())));
            vo.setTotalIntAmt((DecimalUtils.convertFenToYuan(Double.valueOf((totalIntAmt)).longValue())));
            vo.setTotalRemPrinAmt((DecimalUtils.convertFenToYuan(Double.valueOf((totalRemPrinAmt)).longValue())));
            vo.setFirstPayAmt(DecimalUtils.convertFenToYuan(Double.valueOf(firstPayAmt).longValue()));
        }
        return vo;
    }


	//计算首付款等信息
	private PrjPrdPaySchMVO getTotalValue(PrjPrdPaySchMVO vo) {
		List<PrjPrdPaySchDVO> detailList = vo.getPrjPrdPaySchDList();
		List<PrjPrdPrpsFeeDetailVO> prjPrdPayDetailList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
		List<PrjPrdPaySchDVO> feeList = new ArrayList<PrjPrdPaySchDVO>();
		List<PrjPrdPaySchDVO> feeDetailList = vo.getFeeDetailList();
		//合计本金、合计利息、合计剩余本金、合计租金
		double totalRntAmt = 0d;//合计租金
		double totalPrinAmt = 0d;//合计本金
		double totalIntAmt = 0d;//合计利息
		double totalRemPrinAmt = 0d;//合计剩余本金
		double firstPayAmt = 0d;//首付款
		Map<Integer, PrjPrdPrpsFeeDetailVO> prdPayMap = new HashMap<Integer, PrjPrdPrpsFeeDetailVO>();
		if (null != vo) {
			//计算首付款
			if (CollectionUtils.isNotEmpty(feeDetailList)) {
				for (PrjPrdPaySchDVO fee : feeDetailList) {
					//首付款
					if (fee.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)) {
						firstPayAmt = DecimalUtils.add(firstPayAmt, fee.getFeeAmt());
						/*if(null!=fee.getActAmt()){
						fee.setActAmt(DecimalUtils.convertFenToYuan(fee.getActAmt()).longValue());
						}
						if(null!=fee.getArAmt()){
							fee.setArAmt(DecimalUtils.convertFenToYuan(fee.getArAmt()).longValue());
						}
						if(null!=fee.getPaidUpAmt()){
							fee.setPaidUpAmt(DecimalUtils.convertFenToYuan(fee.getPaidUpAmt()).longValue());
						}*/
					}
					fee.setFeeAmt(null == fee.getFeeAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf((fee.getFeeAmt())).longValue()));
					feeList.add(fee);
				}
			}
			if (CollectionUtils.isNotEmpty(detailList)) {
				for (PrjPrdPaySchDVO detail : detailList) {
					if (!prdPayMap.containsKey(detail.getPayPd())) {
						PrjPrdPrpsFeeDetailVO feeDetail = new PrjPrdPrpsFeeDetailVO();
						feeDetail.setPayPd(detail.getPayPd());
						feeDetail.setIsModify(detail.getIsModify());
						feeDetail.setPayDt(detail.getPayDt());
						if (detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
							//租金
							totalRntAmt = DecimalUtils.add(totalRntAmt, detail.getFeeAmt());
							feeDetail.setRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
						}
						if (detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)) {
							//	利息
							totalIntAmt = DecimalUtils.add(totalIntAmt, detail.getFeeAmt());
							feeDetail.setIntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
						}
						if (detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)) {
							//本金
							totalPrinAmt = DecimalUtils.add(totalPrinAmt, detail.getFeeAmt());
							feeDetail.setPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
						}
						if (detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_REMPRIN_PRICE)) {
							//剩余本金
							totalRemPrinAmt = DecimalUtils.add(totalRemPrinAmt, detail.getFeeAmt());
							feeDetail.setRemPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
						}
						prdPayMap.put(detail.getPayPd(), feeDetail);
					} else {
						if (detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
							//租金
							totalRntAmt = DecimalUtils.add(totalRntAmt, detail.getFeeAmt());
							prdPayMap.get(detail.getPayPd()).setRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
						}
						if (detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)) {
							//	利息
							totalIntAmt = DecimalUtils.add(totalIntAmt, detail.getFeeAmt());
							prdPayMap.get(detail.getPayPd()).setIntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
						}
						if (detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)) {
							//本金
							totalPrinAmt = DecimalUtils.add(totalPrinAmt, detail.getFeeAmt());
							prdPayMap.get(detail.getPayPd()).setPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
						}
						if (detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_REMPRIN_PRICE)) {
							//剩余本金
							totalRemPrinAmt = DecimalUtils.add(totalRemPrinAmt, detail.getFeeAmt());
							prdPayMap.get(detail.getPayPd()).setRemPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
						}
					}

				}
			}
			for (Integer key : prdPayMap.keySet()) {
				prjPrdPayDetailList.add(prdPayMap.get(key));
			}

			sortPrjPrdPayList(prjPrdPayDetailList);
			vo.setPrjPrdPayDetailList(prjPrdPayDetailList);
			vo.setFeeDetailList(feeList);
			vo.setActLsAmt(null == vo.getActLsAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf((vo.getActLsAmt())).longValue()));
			vo.setContAmt(null == vo.getContAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf((vo.getContAmt())).longValue()));
			vo.setEachEstRntAmt(null == vo.getEachEstRntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf((vo.getEachEstRntAmt())).longValue()));
			vo.setTotLsItmAmt(null == vo.getTotLsItmAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf((vo.getTotLsItmAmt())).longValue()));
			vo.setTotalRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((totalRntAmt)).longValue()));
			vo.setTotalRemPrinAmt((DecimalUtils.convertFenToYuan(Double.valueOf((totalRemPrinAmt)).longValue())));
			vo.setTotalPrinAmt((DecimalUtils.convertFenToYuan(Double.valueOf((totalPrinAmt)).longValue())));
			vo.setTotalIntAmt((DecimalUtils.convertFenToYuan(Double.valueOf((totalIntAmt)).longValue())));
			vo.setTotalRemPrinAmt((DecimalUtils.convertFenToYuan(Double.valueOf((totalRemPrinAmt)).longValue())));
			vo.setFirstPayAmt(DecimalUtils.convertFenToYuan(Double.valueOf(firstPayAmt).longValue()));
			//vo.setThdPayAmt(null==vo.getThdPayAmt()?0:DecimalUtils.convertFenToYuan(Double.valueOf(vo.getThdPayAmt()).longValue()).longValue());
			//结清数据分转元
			vo.setOverdueAmt(null == vo.getOverdueAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getOverdueAmt()).longValue()));
			vo.setPenaltyAmt(null == vo.getPenaltyAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getPenaltyAmt()).longValue()));
			vo.setActualAmt(null == vo.getActualAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getActualAmt()).longValue()));
			vo.setBeforeSettRntAmt(null == vo.getBeforeSettRntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getBeforeSettRntAmt()).longValue()));
			vo.setDetAmt(null == vo.getDetAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getDetAmt()).longValue()));
			vo.setInsDep(null == vo.getInsDep() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getInsDep()).longValue()));
			vo.setFinalPayAmt(null == vo.getFinalPayAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getFinalPayAmt()).longValue()));
			vo.setLastRntAmt(null == vo.getLastRntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getLastRntAmt()).longValue()));
			vo.setLastPrintAmt(null == vo.getLastPrintAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getLastPrintAmt()).longValue()));
			vo.setLastIntAmt(null == vo.getLastIntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getLastIntAmt()).longValue()));
			vo.setOtherAmt(null == vo.getOtherAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getOtherAmt()).longValue()));
			vo.setPayAmount(null == vo.getPayAmount() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getPayAmount()).longValue()));
			//vo.setTotalFirstPayAmt(vo.getTotalFirstPayAmt()==null?0:DecimalUtils.convertFenToYuan(Double.valueOf(vo.getTotalFirstPayAmt()).longValue()));
			vo.setRickDep(null == vo.getRickDep() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getRickDep()).longValue()));
			vo.setCheckPayAmt(null == vo.getCheckPayAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getCheckPayAmt()).longValue()));
			vo.setTotalActPrinAmt(null == vo.getTotalActPrinAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getTotalActPrinAmt()).longValue()));
			vo.setTotalActIntAmt(null == vo.getTotalActIntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getTotalActIntAmt()).longValue()));
			vo.setTotalSettAmt(null == vo.getTotalSettAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getTotalSettAmt()).longValue()));
			vo.setBeforeSettLastIntAmt(null == vo.getBeforeSettLastIntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getBeforeSettLastIntAmt()).longValue()));
			vo.setBeforeSettLastPrintAmt(null == vo.getBeforeSettLastPrintAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getBeforeSettLastPrintAmt()).longValue()));
			vo.setBreachAmt(null == vo.getBreachAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getBreachAmt()).longValue()));
			vo.setDiscountAmt(null == vo.getDiscountAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getDiscountAmt()).longValue()));
			vo.setDiscountAmt1(null == vo.getDiscountAmt1() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getDiscountAmt1()).longValue()));
			vo.setFromSettLastRntAmt(null == vo.getFromSettLastRntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getFromSettLastRntAmt()).longValue()));
			vo.setCurrentIntAmt(null == vo.getCurrentIntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getCurrentIntAmt()).longValue()));
			vo.setTotalActRntAmt(null == vo.getTotalActRntAmt() ? 0 : DecimalUtils.convertFenToYuan(Double.valueOf(vo.getTotalActRntAmt()).longValue()));
		}
		return vo;
	}


	private PrjPrdPaySchMVO convertPrjQuatPrpsYuanToFen(PrjPrdPaySchMVO prjPrdPay) {
		if(null!=prjPrdPay){
			prjPrdPay.setTotalRntAmt(DecimalUtils.convertYuanToFen(prjPrdPay.getTotalRntAmt()).doubleValue());
			prjPrdPay.setTotalPrinAmt(DecimalUtils.convertYuanToFen(prjPrdPay.getTotalPrinAmt()).doubleValue());
			prjPrdPay.setTotalIntAmt(DecimalUtils.convertYuanToFen(prjPrdPay.getTotalIntAmt()).doubleValue());
			prjPrdPay.setTotalRemPrinAmt(DecimalUtils.convertYuanToFen(prjPrdPay.getTotalRemPrinAmt()).doubleValue());
			prjPrdPay.setFirstPayAmt(DecimalUtils.convertYuanToFen(prjPrdPay.getFirstPayAmt()).doubleValue());
			prjPrdPay.setTotLsItmAmt(DecimalUtils.convertYuanToFen( prjPrdPay.getTotLsItmAmt()).doubleValue());
			prjPrdPay.setContAmt(DecimalUtils.convertYuanToFen( prjPrdPay.getContAmt()).doubleValue());
			prjPrdPay.setActLsAmt(DecimalUtils.convertYuanToFen(prjPrdPay.getActLsAmt()).doubleValue());
			prjPrdPay.setEachEstRntAmt(DecimalUtils.convertYuanToFen(prjPrdPay.getEachEstRntAmt()).doubleValue());
			 List<PrjPrdPaySchDVO> feeList = prjPrdPay.getFeeDetailList();//项目费用明细
		     List<PrjPrdPaySchDVO> payList = prjPrdPay.getPrjPrdPaySchDList();//项目支付表信息
				 for (PrjPrdPaySchDVO pay : payList) {
					 pay.setFeeAmt(DecimalUtils.convertYuanToFen(pay.getFeeAmt()).doubleValue());
				 }
				 for (PrjPrdPaySchDVO detail : feeList) {
					 detail.setFeeAmt(DecimalUtils.convertYuanToFen(detail.getFeeAmt()).doubleValue());
				 }
		}
		return prjPrdPay;
	}
	@Override
	public PrjPrdPaySchMVO prjQuatPrpsCalculate(PrjPrdPaySchMVO entity) throws BaseException {
		if(null==entity){
			throw new  BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		PrjPrdPaySchMVO vo = PrjPrdPaySchMVOTransform.toVO(prjPrdPaySchMApiService.prjQuatPrpsCalculate(PrjPrdPaySchMVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd()));
		getTotalValue(vo);
		return vo;
	}

	@Override
	public PrjPrdPaySchMVO initPrjPrdPaySchMCalculate(Long prjId, Long prjPrdId, Long prjPrdDtlId)
			throws BaseException {
		PrjPrdPaySchMVO prjPrdPay = null;
		if(StringUtils.isNotEmpty(prjPrdId)&&StringUtils.isNotEmpty(prjId)){
			//查询合同编号，没有生成合同编号
			PrjBscInfoVO prjBscInfo = this.prjBscInfoService.selectById(prjId);
			String contractCode = "";
			if(null!=prjBscInfo){
				if(StringUtils.isNotEmpty(prjBscInfo.getLsCntNo())){
					contractCode = prjBscInfo.getLsCntNo();
				}else{
					//生成合同编号
					contractCode = this.prjBscInfoService.generateContractCode(prjId, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
					prjBscInfo.setLsCntNo(contractCode);
					this.prjBscInfoService.modify(prjBscInfo);
				}
			}

			//本项目下的产品列表
			PrjPrdBscInfoQueryCondition prjPrdQc = new  PrjPrdBscInfoQueryCondition();
			prjPrdQc.setPrjId(prjId);
			List<PrjPrdBscInfoVO> prjPrdInfoList = this.prjPrdBscInfoService.searchList(prjPrdQc);
			//总金额
			double totalAmt = 0d;
			//总数量
			int totalNum = 0;
			//已经拆分的金额
			double splitedAmt = 0d;
			//已经拆分的数量
			int splitedNum=0;
			if(CollectionUtils.isNotEmpty(prjPrdInfoList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoDTO : prjPrdInfoList) {
					totalAmt = DecimalUtils.add(totalAmt, DecimalUtils.mul(prjPrdBscInfoDTO.getPrdQty(), prjPrdBscInfoDTO.getPrdAmt()));
					totalNum +=prjPrdBscInfoDTO.getPrdQty();
					PrjPrdDtlQueryCondition prjPrdDtlQc = new PrjPrdDtlQueryCondition();
					prjPrdDtlQc.setPrjPrdId(prjPrdBscInfoDTO.getId());
					List<PrjPrdDtlVO> prjPrdDtls  = this.prjPrdDtlService.selectList(prjPrdDtlQc);
					if(CollectionUtils.isNotEmpty(prjPrdDtls)){
						for (PrjPrdDtlVO prjPrdDtl : prjPrdDtls) {
							if(null!=prjPrdDtl.getPaySchId()){
								splitedNum += prjPrdDtl.getPrdQty();
								splitedAmt = DecimalUtils.add(splitedAmt,prjPrdBscInfoDTO.getPrdAmt());
							}
						}
					}
				}
			}
			PrjPrdBscInfoVO prjPrdInfo = this.prjPrdBscInfoService.selectById(prjPrdId);
				//查询可用的项目方案
				PrjQuatPrpsQueryCondition quatPrpsQc = new PrjQuatPrpsQueryCondition();
				quatPrpsQc.setPrjId(prjId);
				quatPrpsQc.setIsFormalPrps(BaseConstant.IS_YESNO_YES);
				Pager page = new Pager();
				page.setCondition(quatPrpsQc);
				Pager pager = this.prjQuatPrpsService.searchListPage(page);
				List<PrjQuatPrpsVO> prjQuatPrpsList =(List<PrjQuatPrpsVO>)pager.getResultList();
				if(CollectionUtils.isNotEmpty(prjQuatPrpsList)){
					PrjQuatPrpsVO quatPrps = prjQuatPrpsList.get(0);//项目方案
					//拆分以后的产品列表
					PrjPrdDtlQueryCondition prjPrdDtlQc = new PrjPrdDtlQueryCondition();
					prjPrdDtlQc.setPrjPrdId(prjPrdId);
					double prdAmt = 0;
					if(totalNum-splitedNum==0){
						//已经是最后的产品了
						prdAmt = totalAmt-splitedAmt;
					}else{
						prdAmt = prjPrdInfo.getPrdAmt();
					}
					   prjPrdPay = new PrjPrdPaySchMVO();
						prjPrdPay.setContAmt(prdAmt);//设备额
						prjPrdPay.setTotLsItmAmt(prdAmt);//每台设备的价格
						prjPrdPay.setAnnIntRatePct(quatPrps.getAnnIntRatePct());//年利率
						prjPrdPay.setPrjId(prjId);
						prjPrdPay.setCstId(prjBscInfo.getCstId());
						prjPrdPay.setLsPd(quatPrps.getLsPd().intValue());//租赁期数
						prjPrdPay.setLsPdUntCd(quatPrps.getLsPdUntCd());//租赁单位
						prjPrdPay.setIntRateRsPct(quatPrps.getIntRateRsPct());//上浮利率
						prjPrdPay.setPayWayCd(quatPrps.getPayWayCd());//支付方式
						prjPrdPay.setLsCalWayCd(quatPrps.getLsCalWayCd());//计算方式
						prjPrdPay.setIntRateWayCd(quatPrps.getIntRateWayCd());//租赁年利率计算方式
						prjPrdPay.setLsCoe(quatPrps.getLsCoe());//租赁系数
						prjPrdPay.setDpstHdlWayCd(quatPrps.getDpstHdlWayCd());//保证金处理方式
						prjPrdPay.setExpHdlWayCd(quatPrps.getExpHdlWayCd());//租赁期满处理方式
						prjPrdPay.setNoPayWayCd(quatPrps.getNoPayWayCd());//不还款处理方式
						prjPrdPay.setIsDel(BaseConstant.IS_YESNO_NO);//是否删除
						prjPrdPay.setMdfTm(new Date());
						prjPrdPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
						prjPrdPay.setCrtTm(new Date());
						prjPrdPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
						prjPrdPay.setPrjPrdDtlId(prjPrdDtlId);
						prjPrdPay.setPaySchNo(contractCode.concat("-").concat("1"));//后期修改为按规则生成

						//查询项目方案中费用项信息
						PrjQuatPrpsFeeQueryCondition feeQc = new PrjQuatPrpsFeeQueryCondition();
						feeQc.setPrpsId(quatPrps.getId());
						//计算产品支付表的费用信息
						List<PrjPrdPaySchDVO> feeList = new ArrayList<PrjPrdPaySchDVO>();
						List<PrjQuatPrpsFeeVO> prjFeeDetailList =  this.prjQuatPrpsFeeService.searchList(feeQc);
						if(CollectionUtils.isNotEmpty(prjFeeDetailList)){
							for (PrjQuatPrpsFeeVO prjQuatPrpsFeeDTO : prjFeeDetailList) {
								PrjPrdPaySchDVO fee = new PrjPrdPaySchDVO();
								fee.setCalBaseCd(prjQuatPrpsFeeDTO.getCalBaseCd());
								fee.setCntWayCd(prjQuatPrpsFeeDTO.getCntWayCd());
								fee.setFeeAmt(prjQuatPrpsFeeDTO.getFeeAmt());
								fee.setFeeTypCd(prjQuatPrpsFeeDTO.getFeeTypCd());
								fee.setFeePct(prjQuatPrpsFeeDTO.getFeePct());
								fee.setIsSysDef(BaseConstant.IS_YESNO_YES);
								fee.setPayPd(PrjQuatPrpsConstant.CODE_PRJ_PRD_PAY_PD);
								feeList.add(fee);
							}
						}
						//将费用转换为项目产品费用
						prjPrdPay.setFeeDetailList(feeList);
						//不等额设置方案费用
						 if(prjPrdPay.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_END_NO_EQUAL)||prjPrdPay.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_BEGI_NO_EQUAL)){
							 prjPrdPay.setIsModify(BaseConstant.IS_YESNO_YES);
							 List<PrjPrdPrpsFeeDetailVO>prdFeeDetail = new ArrayList<PrjPrdPrpsFeeDetailVO>();
							 PrjQuatPrpsPaySchQueryCondition prjQuatPrpsQc = new PrjQuatPrpsPaySchQueryCondition();
							 prjQuatPrpsQc.setPrpsId(quatPrps.getId());
							List<PrjQuatPrpsPaySchVO> prjQuatPrpsPayList =  this.prjQuatPrpsPaySchService.searchList(prjQuatPrpsQc);
							if(CollectionUtils.isNotEmpty(prjQuatPrpsPayList)){
								for (PrjQuatPrpsPaySchVO prjQuatPrpsPaySchVO : prjQuatPrpsPayList) {
									PrjPrdPrpsFeeDetailVO prdFee = PrjQuatPrpsPaySchVOTransform.toPrjPrdFeeVO(prjQuatPrpsPaySchVO);
									prdFeeDetail.add(prdFee);
								}
							}
							prjPrdPay.setPrjPrdPayDetailList(prdFeeDetail);
						}
						prjPrdPay =this.prjQuatPrpsCalculate(prjPrdPay);

				}

			}

		return prjPrdPay;
	}

	private List<PrjPrdPrpsFeeDetailVO>sortPrjPrdPayList(List<PrjPrdPrpsFeeDetailVO> prjPrdPayList){
        Collections.sort(prjPrdPayList, new Comparator<PrjPrdPrpsFeeDetailVO>(){
            public int compare(PrjPrdPrpsFeeDetailVO o1, PrjPrdPrpsFeeDetailVO o2) {
                if(o1.getPayPd().intValue() > o2.getPayPd().intValue()){
                    return 1;
                }
                if(o1.getPayPd().intValue() == o2.getPayPd().intValue()){
                    return 0;
                }
                return -1;
            }
      });
        return prjPrdPayList;
	}
	@Override
	public void setPrjPrdSchMPayDate(Long prjPrdId, Date firstPayDate) throws BaseException {
		if(StringUtils.isEmpty(prjPrdId)||null==firstPayDate){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"支付日期参数不能为空！");
		}
		this.prjPrdPaySchMApiService.setPrjPrdSchMPayDate(prjPrdId, firstPayDate, CurrentThreadContext.getCurrentBuOrgCd());
	}

	@Override
	public void modifyPrjPrdSchMPayDate(Long prjPrdPayId, Date rentDate) throws BaseException {
		if(StringUtils.isEmpty(prjPrdPayId)||null==rentDate){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"支付日期参数不能为空！");
		}
		this.prjPrdPaySchMApiService.modifyPrjPrdSchMPayDate(prjPrdPayId, rentDate, CurrentThreadContext.getCurrentBuOrgCd());
	}

	@Override
	public Pager selectPrjPrdPaySchMMgrListPage(Pager page) throws BaseException {
		if(null==page) return new Pager();
		Pager pager= prjPrdPaySchMApiService.selectPrjPrdPaySchMMgrListPage(page);
		if(CollectionUtils.isNotEmpty(pager.getResultList())){
			List<PrjPrdPaySchMVO> list = PrjPrdPaySchMVOTransform.toVOList((List<PrjPrdPaySchMDTO>)pager.getResultList());
			pager.setResultList(list);
		}
		return pager;
	}

    @Override
    public Pager selectPrjPrdZfPaySchMMgrListPage(Pager page) throws BaseException {
        if(null==page) return new Pager();
        Pager pager= prjPrdPaySchMApiService.selectPrjPrdZfPaySchMMgrListPage(page);
        if(CollectionUtils.isNotEmpty(pager.getResultList())){
            List<PrjPrdPaySchMVO> list = PrjPrdPaySchMVOTransform.toVOList((List<PrjPrdPaySchMDTO>)pager.getResultList());
            pager.setResultList(list);
        }
        return pager;
    }

	@Override
	public void exportRentNotice(Long paySchId, ByteArrayOutputStream out) throws BaseException {

		if(null==paySchId){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表ID不能为空!");
		}
		Document document = null;
		PrjPrdPaySchMVO schM = 	this.selectPrjPrdPaySchMAndDetailById(paySchId);
		String lsCnNo ="";
		String cstNm = "";
		if(null!=schM){
			if(null!=schM.getPrjId()){
				PrjBscInfoVO prjBsc = this.prjBscInfoService.selectById(schM.getPrjId());
				lsCnNo = prjBsc.getLsCntNo()==null?"":prjBsc.getLsCntNo();
			}
			if(null!=schM.getCstId()){
				CstBscInfoVO cst = this.cstBscInfoService.selectDetailById(schM.getCstId());
				if(null!=cst){
					cstNm = cst.getCstNm()==null?"":cst.getCstNm();
				}
			}
		}
		try {
			//定义Cell边框粗细   顺序是：上下左右
 	float[] borderStart = {0.5f,0.5f,0.5f,0} ;
 	float[] borderRight = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderEnd = {0.5f,0,0.5f,0.5f} ;
 	float[] borderFootRight = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderStart1 = {0.5f,0.5f,0.5f,0} ;
 	float[] borderEnd1 = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderStart2 = {0,0.5f,0.5f,0} ;
 	float[] borderEnd2 = {0,0,0,0} ;
 	float[] borderStart3 = {0,0,0,0} ;
 	//定义默认字体
 	int[] fontDefault = {-1,-1} ;
 	int[] fontDateDefault = new int[]{9,Font.NORMAL};
 	//定义默认边距   顺序是：上下左右
 	float[] paddingDefault = {3f,3f,2f,2f};
 	//定义默认位置    水平，垂直
 	int [] alignDefault = {-1,-1} ;//靠左
 	int [] alignCenter = {PdfPCell.ALIGN_CENTER,PdfPCell.ALIGN_CENTER} ;//居中
 	int [] alignRight = {PdfPCell.ALIGN_RIGHT,PdfPCell.ALIGN_CENTER} ;//靠右
 	int [] alignLift = {PdfPCell.ALIGN_LEFT,PdfPCell.ALIGN_CENTER} ;//靠左

 // 字体设置
    BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.EMBEDDED);
    Font FontColumn2 = new Font(bfChinese, 10, Font.BOLD);
    Font FontDefault22 = new Font(bfChinese, 5, Font.NORMAL);
    Font FontTitle= new Font(bfChinese,10,Font.UNDERLINE);
    Font FontDefault2 = new Font(bfChinese, 10, Font.NORMAL);
    Font FontDefault = new Font(bfChinese, 15, Font.NORMAL);
    Font FontDefaultbig = new Font(bfChinese, 20, Font.BOLD);
    Font fa = new Font(bfChinese, 12, Font.BOLD);
    // 数字格式
    NumberFormat nfFSNum = new DecimalFormat("###########0.00");
    NumberFormat nfcFSNum = new DecimalFormat("###,###,###,##0.00");
    nfFSNum.setGroupingUsed(true);
    nfFSNum.setMaximumFractionDigits(2);
     document = new Document(PageSize.A4,22,22,30,10); // 其余4个参数，设置了页面的4个边距
    document.setMarginMirroring(true);
    PdfWriter.getInstance(document, out);
    // 打开文档
    document.open();
    PdfPCell cell=new PdfPCell();
	cell.setBorder(0);
	cell.setColspan(1);

	cell.setHorizontalAlignment(1);
	cell.setVerticalAlignment(1);
	PdfPTable tT = new PdfPTable(8);
	tT.setWidthPercentage(100f);
	tT.addCell(cell);
	tT.addCell(PdfExportServer.createCell("狮桥租赁",PdfPCell.ALIGN_LEFT, FontDefault22,5));
	tT.addCell(PdfExportServer.createCell("起租通知书",PdfPCell.ALIGN_RIGHT, FontDefault22,2));
	Phrase objPhase = new Phrase(" ", FontDefault);
	PdfPCell objCell = new PdfPCell(objPhase);
	objCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	objCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
	objCell.setColspan(8);
	objCell.setBorderWidthBottom(0);
	objCell.setBorderWidthLeft(0);
	objCell.setBorderWidthRight(0);
	tT.addCell(objCell);
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));

	tT.addCell(PdfExportServer.createCell("起租通知书", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));

	tT.addCell(PdfExportServer.createCell(" ",PdfPCell.ALIGN_LEFT, FontColumn2,8));
	String lsDate = schM.getLsDt()==null?" ":DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD);

	tT.addCell(PdfExportServer.createCell("          按照贵我双方签署的合同编号为：( "+lsCnNo+" )《设备融资租赁合同》和贵我双方签署的编号为：( ",PdfPCell.ALIGN_LEFT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell(" )《设备融资租赁合同委托采购协议》，相关设备已经贵司验收合格，起租日为 ( "+lsDate+" )", PdfPCell.ALIGN_LEFT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell("请按《租金支付表》所列的时间及金额支付租金。",PdfPCell.ALIGN_LEFT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell("",PdfPCell.ALIGN_LEFT, FontDefault2,8));

	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("           请贵公司予以签字盖章确认并将其中一份回执我公司，特此通知。",PdfPCell.ALIGN_LEFT, FontDefault2,8));

	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("出租人："+cstNm,PdfPCell.ALIGN_RIGHT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("（盖 章）                                                                                    ",PdfPCell.ALIGN_RIGHT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("       年                 月                 日                                       ",PdfPCell.ALIGN_RIGHT, FontDefault2,8));

	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("	在此同意和确认：",PdfPCell.ALIGN_LEFT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("                                 （公 章）",PdfPCell.ALIGN_LEFT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell(" 法定代表人：                                                               （签字或盖章）                                  ",PdfPCell.ALIGN_LEFT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell(" （或委托代理人） ",PdfPCell.ALIGN_LEFT, FontDefault2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2,8));
	tT.addCell(PdfExportServer.createCell("       年                 月                 日                                                                                 ",PdfPCell.ALIGN_RIGHT, FontDefault2,8));

  	 document.add(tT);
  	 document.add(Chunk.NEXTPAGE);
	//-------------------------------第二页--------------------------------------------------------//


		PdfPTable tT4 = new PdfPTable(10);
		tT4.setWidthPercentage(100f);
		tT4.setWidthPercentage(100f);
		tT4.addCell(cell);
		tT4.addCell(PdfExportServer.createCell("狮桥租赁",PdfPCell.ALIGN_LEFT, FontDefault22,4));
		tT4.addCell(PdfExportServer.createCell("租金支付表",PdfPCell.ALIGN_RIGHT, FontDefault22,6));

		Phrase tObjPhase = new Phrase("  ", FontDefault2);
		PdfPCell tCell = new PdfPCell(tObjPhase);
		tCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		tCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
		tCell.setColspan(10);
		tCell.setBorderWidthBottom(0);
		tCell.setBorderWidthLeft(0);
		tCell.setBorderWidthRight(0);
		tT4.addCell(tCell);

		tT4.addCell(PdfExportServer.createCell("附件2：",PdfPCell.ALIGN_LEFT, FontDefault2,10));
		tT4.addCell(PdfExportServer.createCell("",PdfPCell.ALIGN_LEFT, FontDefault2,10));

		tT4.addCell(PdfExportServer.createCell("租金支付表",PdfPCell.ALIGN_CENTER, FontDefaultbig,10));
		tT4.addCell(PdfExportServer.createCell("",PdfPCell.ALIGN_CENTER, FontColumn2,10));
		tT4.addCell(PdfExportServer.createCell("",PdfPCell.ALIGN_LEFT, FontDefault2,10));
	    tT4.addCell(PdfExportServer.createCell(bfChinese, "  " , fontDateDefault, paddingDefault, borderStart3,alignCenter, 10)) ;


		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁资产规模" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt()==null?"": schM.getTotLsItmAmt().toString(), fontDateDefault, paddingDefault, borderRight,alignCenter, 2)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁年利率" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getAnnIntRatePct()==null?"": schM.getAnnIntRatePct().toString()+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   //查询管理费
		   double mgrPct =0d;
		   double mgrAmt = 0d;
		  List<PrjPrdPaySchDVO> feeList =  schM.getFeeDetailList();
		   for (PrjPrdPaySchDVO fee : feeList) {
				if(fee.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_MGR)){
					mgrPct = fee.getFeePct()==null?0:Double.valueOf(fee.getFeePct());
					mgrPct = fee.getFeeAmt()==null?0:Double.valueOf(fee.getFeeAmt());
				}
		   }
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "管理费" , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, mgrPct+"" , fontDateDefault, paddingDefault, borderEnd,alignCenter, -1)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租金计算方式" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getPayWayCdNm() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租金支付期次" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsPd()==null?"":schM.getLsPd().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "起租日" , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsDt()==null?"":DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD) , fontDateDefault, paddingDefault, borderRight,alignCenter, -1)) ;


		   tT4.addCell(PdfExportServer.createCell(bfChinese,"每期支付金额（元）",new int[]{10,Font.BOLD}, paddingDefault, borderEnd1, alignCenter, 10)) ;
		   if(schM.getPrjPrdPaySchDList().size()>0 && schM.getPrjPrdPaySchDList()!=null)
		       {
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "期数" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "租金支付日期" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "每期支付租金" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁管理费" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "合计" , fontDefault, paddingDefault, borderEnd,alignCenter, 2)) ;
				   //数据行
				   for(int i=0;i<schM.getPrjPrdPaySchDList().size();i++)
				   {
					   PrjPrdPaySchDVO pay = schM.getPrjPrdPaySchDList().get(i);
					   if(pay.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)){
						   double total = 0d;
						   double payMgrAmt = 0d;
						   if(pay.getPayPd()==1){
							   total =DecimalUtils.add(pay.getFeeAmt(), mgrAmt);
							   payMgrAmt = mgrAmt;
						   }else{
							   total = pay.getFeeAmt();
						   }
						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getPayPd()==null?"":pay.getPayPd().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getPayDt()==null?"":DateUtils.formatDateToString(pay.getPayDt(), DateUtils.YYYY_MM_DD) , fontDateDefault, paddingDefault, borderStart,alignCenter,2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getFeeAmt()==null?"":pay.getFeeAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, payMgrAmt+"" , fontDateDefault, paddingDefault, borderStart,alignCenter,2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, total+"" , fontDateDefault, paddingDefault, borderRight,alignCenter, 2)) ;
					   }
				   }
		       }
		   double totalRntAndMgr = 0d;
		   totalRntAndMgr = (schM.getTotalRntAmt()==null?0:schM.getTotalRntAmt())+mgrAmt;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "总计", fontDateDefault, paddingDefault, borderStart,alignCenter, 4)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotalRntAmt()==null?"":schM.getTotalRntAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, mgrAmt+"" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, totalRntAndMgr+"" , fontDateDefault, paddingDefault, borderRight,alignCenter, 2)) ;
		   document.add(tT4);
		} catch (Exception e) {
		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_405_NAME,"导出起租通知书，文件处理错误！");
	}finally {
        try {
            document.close();
        } catch (Exception e) {
            //可能之前已经关闭过了
        }
    }
}

	@Override
	public void exportFirstPayAmt(Long paySchId, ByteArrayOutputStream out) throws BaseException {

		if(null==paySchId){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表ID不能为空!");
		}
		Document document = null;
		PrjPrdPaySchMVO schM = 	this.selectPrjPrdPaySchMAndDetailById(paySchId);
		String lsCnNo ="";
		String cstNm = "";
		PrjBscInfoVO prjBsc = null;
		if(null!=schM){
			if(null!=schM.getPrjId()){
				 prjBsc = this.prjBscInfoService.selectById(schM.getPrjId());
				lsCnNo = prjBsc.getLsCntNo()==null?"":prjBsc.getLsCntNo();
			}
			if(null!=schM.getCstId()){
				CstBscInfoVO cst = this.cstBscInfoService.selectDetailById(schM.getCstId());
				if(null!=cst){
					cstNm = cst.getCstNm()==null?"":cst.getCstNm();
				}
			}
		try {
			//定义Cell边框粗细   顺序是：上下左右
 	float[] borderStart = {0.5f,0.5f,0.5f,0} ;
 	float[] borderRight = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderEnd = {0.5f,0,0.5f,0.5f} ;
 	float[] borderFootRight = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderStart1 = {0.5f,0.5f,0.5f,0} ;
 	float[] borderEnd1 = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderStart2 = {0,0,0.5f,0} ;
 	float[] borderEnd2 = {0,0,0,0} ;
 	float[] borderStart3 = {0,0,0,0} ;
 	//定义默认字体
 	int[] fontDefault = {-1,-1} ;
 	int[] fontDateDefault = new int[]{9,Font.NORMAL};
 	//定义默认边距   顺序是：上下左右
 	float[] paddingDefault = {3f,3f,2f,2f};
 	//定义默认位置    水平，垂直
 	int [] alignDefault = {-1,-1} ;//靠左
 	int [] alignCenter = {PdfPCell.ALIGN_CENTER,PdfPCell.ALIGN_CENTER} ;//居中
 	int [] alignRight = {PdfPCell.ALIGN_RIGHT,PdfPCell.ALIGN_CENTER} ;//靠右
 	int [] alignLift = {PdfPCell.ALIGN_LEFT,PdfPCell.ALIGN_CENTER} ;//靠左

 // 字体设置
    BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.EMBEDDED);
    Font FontColumn2 = new Font(bfChinese, 10, Font.BOLD);
    Font FontDefault22 = new Font(bfChinese, 5, Font.NORMAL);
    Font FontTitle= new Font(bfChinese,10,Font.UNDERLINE);
    Font FontDefault2 = new Font(bfChinese, 10, Font.NORMAL);
    Font FontDefault = new Font(bfChinese, 15, Font.NORMAL);
    Font FontDefaultbig = new Font(bfChinese, 20, Font.BOLD);
    Font fa = new Font(bfChinese, 12, Font.BOLD);
    // 数字格式
    NumberFormat nfFSNum = new DecimalFormat("###########0.00");
    NumberFormat nfcFSNum = new DecimalFormat("###,###,###,##0.00");
    nfFSNum.setGroupingUsed(true);
    nfFSNum.setMaximumFractionDigits(2);
     document = new Document(PageSize.A4,22,22,30,10); // 其余4个参数，设置了页面的4个边距
    document.setMarginMirroring(true);
    PdfWriter.getInstance(document, out);
    // 打开文档
    document.open();
    PdfPCell cell=new PdfPCell();
	cell.setBorder(0);
	cell.setColspan(1);

	cell.setHorizontalAlignment(1);
	cell.setVerticalAlignment(1);

		PdfPTable tT4 = new PdfPTable(10);
		tT4.setWidthPercentage(100f);
		tT4.setWidthPercentage(100f);
		tT4.addCell(cell);

		tT4.addCell(PdfExportServer.createCell("支付表首期款明细表",PdfPCell.ALIGN_CENTER, FontDefaultbig,10));
		tT4.addCell(PdfExportServer.createCell("",PdfPCell.ALIGN_CENTER, FontColumn2,10));
		tT4.addCell(PdfExportServer.createCell("",PdfPCell.ALIGN_LEFT, FontDefault2,10));
		tT4.addCell(PdfExportServer.createCell(bfChinese, " " , fontDateDefault, paddingDefault, borderStart3,alignCenter, 10)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "支付表号：" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getPaySchNo()==null?"":schM.getPaySchNo(), fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "融资合同：" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, lsCnNo, fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;


		   tT4.addCell(PdfExportServer.createCell(bfChinese, "承租人：" , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, cstNm , fontDateDefault, paddingDefault, borderRight,alignCenter, -1)) ;

		   PdfPCell titCell =   PdfExportServer.createCell(bfChinese, "租赁物清单" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2);
		   titCell.setRowspan(2);
		   tT4.addCell(titCell) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物名称" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "型号" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "整机编号" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "单价" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "数量" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "留购价" , fontDefault, paddingDefault, borderEnd,alignCenter, 2)) ;

		   PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
		   dtlQc.setPaySchId(paySchId);
		   List<PrjPrdDtlVO> dtlList =   this.prjPrdDtlService.selectList(dtlQc);
		   PrjPrdDtlVO dtl = null;
		   double price = 0d;
		   double  rsrvPc = 0d;
		  // String machNo = "";
		   if(CollectionUtils.isNotEmpty(dtlList)){
			   dtl = dtlList.get(0);
			   if(null!=dtl.getPrjPrdId()){
				   PrjPrdBscInfoVO prjPrd =    this.prjPrdBscInfoService.selectById(dtl.getPrjPrdId());
				   if(null!=prjPrd){
					   price = prjPrd.getGuidePc()==null?0:prjPrd.getGuidePc();
					   rsrvPc = prjPrd.getRsrvPc()==null?0:prjPrd.getRsrvPc();
				   }
			   }
			 /*  if(null!=dtl.getActPrdId()){
				   //查询合格证信息
				   PrjPrdVehInfoVO veh =   this.prjPrdVehInfoService.selectById(dtl.getActPrdId());
				   if(null!=veh){
					   machNo = veh.getMachNo();
				   }
			   }*/
		   }else{
			   dtl = new PrjPrdDtlVO();
		   }
		   List<PrjPrdPaySchDVO> detailList = schM.getFeeDetailList();
		   double depPct = 0d;//保证金比例
		   double firstPct = 0d;//首期款比例
		   double  suggPct = 0d;//咨询费1比例
		   if(CollectionUtils.isNotEmpty(detailList)){
			   for (PrjPrdPaySchDVO prjPrdPaySchDVO : detailList) {
					if(prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DEP)){
						depPct = prjPrdPaySchDVO.getFeePct()==null?0:prjPrdPaySchDVO.getFeePct();
					}
					if(prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_SUGG)){
						suggPct = prjPrdPaySchDVO.getFeePct()==null?0:prjPrdPaySchDVO.getFeePct();
					}
					if(prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DOWNPAY)){
						firstPct = prjPrdPaySchDVO.getFeePct()==null?0:prjPrdPaySchDVO.getFeePct();
					}
			   }
		   }

		   //查询日罚息率
		   String punish = "";
		  List<SysDictionaryDTO> list =   this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), prjBsc.getCstMgrOrgCd(), CapitalConstant.CODE_CAP_OVERDUE_RATE_CD);
		   if(CollectionUtils.isNotEmpty(list)){
			   punish = list.get(0).getCode();
		   }

		   tT4.addCell(PdfExportServer.createCell(bfChinese, dtl.getPrdNm()==null?"":dtl.getPrdNm() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, dtl.getPrdMdl()==null?"":dtl.getPrdMdl() , fontDateDefault, paddingDefault, borderStart,alignCenter,2)) ;
		//   tT4.addCell(PdfExportServer.createCell(bfChinese, machNo , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, price+"" , fontDateDefault, paddingDefault, borderStart,alignCenter,-1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese,dtl.getPrdQty()==null?" ":dtl.getPrdQty().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese,rsrvPc+"", fontDateDefault, paddingDefault, borderRight,alignCenter, 2)) ;
		   //-------------------------------------------------支付表主表信息----------------------------------------------------------------------------------------//
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物总价值" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt()==null?"":schM.getTotLsItmAmt().toString(), fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "大写" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt()==null?"": ProjectUtils.hangeToBig(schM.getTotLsItmAmt()), fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;


		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物保证金比例" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, depPct+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁期数" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsDt()==null?"":DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "首期租金比例" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, firstPct+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;
		   Integer period = ProjectUtils.getRentPeriod(schM.getLsPd().intValue(), Integer.valueOf(schM.getLsPdUntCd()));

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁周期（月）" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, period==null?"": period+"", fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "咨询费1比例" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, suggPct+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "日罚息率" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese,  punish+"%", fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "利率上浮比例" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getIntRateRsPct()==null?"": schM.getIntRateRsPct().toString()+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁年利率" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getAnnIntRatePct()==null?"": schM.getAnnIntRatePct().toString()+"%", fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "实际租赁物价值" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt()==null?"": schM.getTotLsItmAmt().toString(), fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "起租日期" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsDt()==null?"": DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "支付方式 " , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getPayWayCdNm()==null?"":schM.getPayWayCdNm(), fontDateDefault, paddingDefault, borderRight,alignCenter, 8)) ;

		   if(detailList.size()>0 && detailList!=null)
		       {
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "首期款名称" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "应收时间" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "费用金额" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "备注" , fontDefault, paddingDefault, borderRight,alignCenter, 4)) ;
				   //数据行
				   for(int i=0;i<detailList.size();i++)
				   {
					   PrjPrdPaySchDVO detail = detailList.get(i);
					   if(detail.getCalBaseCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)){
						   tT4.addCell(PdfExportServer.createCell(bfChinese, detail.getFeeTypCdNm()==null?"":detail.getFeeTypCdNm() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, detail.getPayDt()==null?"":DateUtils.formatDateToString(detail.getPayDt(), DateUtils.YYYY_MM_DD) , fontDateDefault, paddingDefault, borderStart,alignCenter,2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, detail.getFeeAmt()==null?"":detail.getFeeAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, " " , fontDateDefault, paddingDefault, borderRight,alignCenter,4)) ;
					   }
				   }
		       }

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "首期款总额", fontDateDefault, paddingDefault, borderStart,alignCenter, 4)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getFirstPayAmt()==null?"":schM.getFirstPayAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "" , fontDateDefault, paddingDefault, borderRight,alignCenter, 4)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "出租人（签字）： " , fontDefault, paddingDefault, borderStart3,alignCenter, 4)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "日期： " , fontDefault, paddingDefault, borderStart3,alignCenter, 6)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "承租人（签字）： " , fontDefault, paddingDefault, borderEnd2,alignCenter, 4)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "日期： " , fontDefault, paddingDefault, borderEnd2,alignCenter, 6)) ;

		   document.add(tT4);
		} catch (Exception e) {
		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_405_NAME,"导出起租通知书，文件处理错误！");
	}finally {
	        try {
	            document.close();
	        } catch (Exception e) {
	            //可能之前已经关闭过了
	        }
			}
		}
	}

	@Override
	public void exportPrjPrdPaySch(Long paySchId, ByteArrayOutputStream out) throws BaseException {

		if(null==paySchId){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表ID不能为空!");
		}
		Document document = null;
		PrjPrdPaySchMVO schM = 	this.selectPrjPrdPaySchMAndDetailById(paySchId);
		String lsCnNo ="";
		String cstNm = "";
		if(null!=schM){
			if(null!=schM.getPrjId()){
				PrjBscInfoVO prjBsc = this.prjBscInfoService.selectById(schM.getPrjId());
				lsCnNo = prjBsc.getLsCntNo()==null?"":prjBsc.getLsCntNo();
			}
			if(null!=schM.getCstId()){
				CstBscInfoVO cst = this.cstBscInfoService.selectDetailById(schM.getCstId());
				if(null!=cst){
					cstNm = cst.getCstNm()==null?"":cst.getCstNm();
				}
			}
		try {
			//定义Cell边框粗细   顺序是：上下左右
 	float[] borderStart = {0.5f,0.5f,0.5f,0} ;
 	float[] borderRight = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderEnd = {0.5f,0,0.5f,0.5f} ;
 	float[] borderFootRight = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderStart1 = {0.5f,0.5f,0.5f,0} ;
 	float[] borderEnd1 = {0.5f,0.5f,0.5f,0.5f} ;
 	float[] borderStart2 = {0,0,0.5f,0} ;
 	float[] borderEnd2 = {0,0,0,0} ;
 	float[] borderStart3 = {0,0,0,0} ;
 	//定义默认字体
 	int[] fontDefault = {-1,-1} ;
 	int[] fontDateDefault = new int[]{9,Font.NORMAL};
 	//定义默认边距   顺序是：上下左右
 	float[] paddingDefault = {3f,3f,2f,2f};
 	//定义默认位置    水平，垂直
 	int [] alignDefault = {-1,-1} ;//靠左
 	int [] alignCenter = {PdfPCell.ALIGN_CENTER,PdfPCell.ALIGN_CENTER} ;//居中
 	int [] alignRight = {PdfPCell.ALIGN_RIGHT,PdfPCell.ALIGN_CENTER} ;//靠右
 	int [] alignLift = {PdfPCell.ALIGN_LEFT,PdfPCell.ALIGN_CENTER} ;//靠左

 // 字体设置
    BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.EMBEDDED);
    Font FontColumn2 = new Font(bfChinese, 10, Font.BOLD);
    Font FontDefault22 = new Font(bfChinese, 5, Font.NORMAL);
    Font FontTitle= new Font(bfChinese,10,Font.UNDERLINE);
    Font FontDefault2 = new Font(bfChinese, 10, Font.NORMAL);
    Font FontDefault = new Font(bfChinese, 15, Font.NORMAL);
    Font FontDefaultbig = new Font(bfChinese, 20, Font.BOLD);
    Font fa = new Font(bfChinese, 12, Font.BOLD);
    // 数字格式
    NumberFormat nfFSNum = new DecimalFormat("###########0.00");
    NumberFormat nfcFSNum = new DecimalFormat("###,###,###,##0.00");
    nfFSNum.setGroupingUsed(true);
    nfFSNum.setMaximumFractionDigits(2);
     document = new Document(PageSize.A4,22,22,30,10); // 其余4个参数，设置了页面的4个边距
    document.setMarginMirroring(true);
    PdfWriter.getInstance(document, out);
    // 打开文档
    document.open();
    PdfPCell cell=new PdfPCell();
	cell.setBorder(0);
	cell.setColspan(1);

	cell.setHorizontalAlignment(1);
	cell.setVerticalAlignment(1);

		PdfPTable tT4 = new PdfPTable(10);
		tT4.setWidthPercentage(100f);
		tT4.setWidthPercentage(100f);
		tT4.addCell(cell);

		tT4.addCell(PdfExportServer.createCell("支付表",PdfPCell.ALIGN_CENTER, FontDefaultbig,10));
		tT4.addCell(PdfExportServer.createCell("",PdfPCell.ALIGN_CENTER, FontColumn2,10));
		tT4.addCell(PdfExportServer.createCell("",PdfPCell.ALIGN_LEFT, FontDefault2,10));
		tT4.addCell(PdfExportServer.createCell(bfChinese, "  " , fontDateDefault, paddingDefault, borderStart3,alignCenter, 10)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "支付表号：" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getPaySchNo()==null?"":schM.getPaySchNo(), fontDateDefault, paddingDefault, borderRight,alignCenter, 2)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "融资合同：" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, lsCnNo, fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;


		   tT4.addCell(PdfExportServer.createCell(bfChinese, "承租人：" , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, cstNm , fontDateDefault, paddingDefault, borderRight,alignCenter, -1)) ;

		   PdfPCell titCell =   PdfExportServer.createCell(bfChinese, "租赁物清单" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2);
		   titCell.setRowspan(2);
		   tT4.addCell(titCell) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物名称" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "型号" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "整机编号" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "单价" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "数量" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "留购价" , fontDefault, paddingDefault, borderRight,alignCenter, 2)) ;

		   PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
		   dtlQc.setPaySchId(paySchId);
		   List<PrjPrdDtlVO> dtlList =   this.prjPrdDtlService.selectList(dtlQc);
		   PrjPrdDtlVO dtl = null;
		   double price = 0;
		   double  rsrvPc = 0d;
		   //String machNo = "";
		   String priceStr ="";
		   if(CollectionUtils.isNotEmpty(dtlList)){
			   dtl = dtlList.get(0);
			   if(null!=dtl.getPrjPrdId()){
				   PrjPrdBscInfoVO prjPrd =    this.prjPrdBscInfoService.getPrjPrdBscInfoById(dtl.getPrjPrdId());
				   if(null!=prjPrd){
					   price = prjPrd.getGuidePc()==null?0:prjPrd.getGuidePc();
					   rsrvPc = prjPrd.getRsrvPc()==null?0:prjPrd.getRsrvPc();
					   BigDecimal bd = new BigDecimal(price);
					    priceStr = bd.toPlainString();
				   }
			   }
			/*   if(null!=dtl.getActPrdId()){
				   //查询合格证信息
				   PrjPrdVehInfoVO veh =   this.prjPrdVehInfoService.selectById(dtl.getActPrdId());
				   if(null!=veh){
					   machNo = veh.getMachNo();
				   }
			   }*/
		   }else{
			   dtl = new PrjPrdDtlVO();
		   }
		   List<PrjPrdPaySchDVO> detailList = schM.getFeeDetailList();
		   double depPct = 0d;//保证金比例
		   double firstPct = 0d;//首期款比例
		   double  suggPct = 0d;//咨询费1比例
		   if(CollectionUtils.isNotEmpty(detailList)){
			   for (PrjPrdPaySchDVO prjPrdPaySchDVO : detailList) {
					if(prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DEP)){
						depPct = prjPrdPaySchDVO.getFeePct()==null?0:prjPrdPaySchDVO.getFeePct();
					}
					if(prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_SUGG)){
						suggPct = prjPrdPaySchDVO.getFeePct()==null?0:prjPrdPaySchDVO.getFeePct();
					}
					if(prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DOWNPAY)){
						firstPct = prjPrdPaySchDVO.getFeePct()==null?0:prjPrdPaySchDVO.getFeePct();
					}
			   }
		   }

		   //查询日罚息率
		   String punish = "";
		  List<SysDictionaryDTO> list =   this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapitalConstant.CODE_CAP_OVERDUE_RATE_CD);
		   if(CollectionUtils.isNotEmpty(list)){
			   punish = list.get(0).getCode();
		   }

		   tT4.addCell(PdfExportServer.createCell(bfChinese, dtl.getPrdNm()==null?"":dtl.getPrdNm() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, dtl.getPrdMdl()==null?"":dtl.getPrdMdl() , fontDateDefault, paddingDefault, borderStart,alignCenter,2)) ;
		  // tT4.addCell(PdfExportServer.createCell(bfChinese, machNo , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, priceStr , fontDateDefault, paddingDefault, borderStart,alignCenter,-1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese,dtl.getPrdQty()==null?" ":dtl.getPrdQty().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese,rsrvPc+"", fontDateDefault, paddingDefault, borderRight,alignCenter, 2)) ;
		   //-------------------------------------------------支付表主表信息----------------------------------------------------------------------------------------//
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物总价值" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt()==null?"":schM.getTotLsItmAmt().toString(), fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "大写" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt()==null?"": ProjectUtils.hangeToBig(schM.getTotLsItmAmt()), fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;


		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物保证金比例" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, depPct+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁期数" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsDt()==null?"":DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "首期租金比例" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, firstPct+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;
		   Integer period = ProjectUtils.getRentPeriod(schM.getLsPd().intValue(), Integer.valueOf(schM.getLsPdUntCd()));

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁周期（月）" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, period==null?"": period+"", fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "咨询费1比例" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, suggPct+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "日罚息率" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese,  punish+"%", fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "利率上浮比例" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getIntRateRsPct()==null?"": schM.getIntRateRsPct().toString()+"%", fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁年利率" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getAnnIntRatePct()==null?"": schM.getAnnIntRatePct().toString()+"%", fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "实际租赁物价值" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt()==null?"": schM.getTotLsItmAmt().toString(), fontDateDefault, paddingDefault, borderStart,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "起租日期" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsDt()==null?"": DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderRight,alignCenter, 3)) ;

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "支付方式 " , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getPayWayCdNm()==null?"":schM.getPayWayCdNm(), fontDateDefault, paddingDefault, borderRight,alignCenter, 8)) ;
		   	double totalRemPrintAmt  =0d;
		   if(schM.getPrjPrdPaySchDList().size()>0 && schM.getPrjPrdPaySchDList()!=null)
		       {
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "期次" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "支付时间" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "租金" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "本金" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "利息" , fontDefault, paddingDefault, borderStart,alignCenter, -1)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "剩余本金" , fontDefault, paddingDefault, borderStart,alignCenter, 2)) ;
			   tT4.addCell(PdfExportServer.createCell(bfChinese, "备注" , fontDefault, paddingDefault, borderRight,alignCenter, 2)) ;
				   //数据行
				   for(int i=0;i<schM.getPrjPrdPayDetailList().size();i++)
				   {
					   PrjPrdPrpsFeeDetailVO pay = schM.getPrjPrdPayDetailList().get(i);

						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getPayPd()==null?"":pay.getPayPd().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getPayDt()==null?"":DateUtils.formatDateToString(pay.getPayDt(), DateUtils.YYYY_MM_DD) , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getRntAmt()==null?"":pay.getRntAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getPrinAmt()==null?"":pay.getPrinAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getIntAmt()==null?"":pay.getIntAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter,-1)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getRemPrinAmt()==null?"":pay.getRemPrinAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
						   tT4.addCell(PdfExportServer.createCell(bfChinese, " " , fontDateDefault, paddingDefault, borderRight,alignCenter,2)) ;
						   totalRemPrintAmt = DecimalUtils.add(totalRemPrintAmt, pay.getRemPrinAmt());
				   }
		       }

		   tT4.addCell(PdfExportServer.createCell(bfChinese, "金额总计", fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotalRntAmt()==null?"":schM.getTotalRntAmt().toString(), fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotalPrinAmt()==null?"":schM.getTotalPrinAmt().toString() , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotalIntAmt()==null?"":schM.getTotalIntAmt().toString(), fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, totalRemPrintAmt+"" , fontDateDefault, paddingDefault, borderStart,alignCenter, 2)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, " " , fontDateDefault, paddingDefault, borderRight,alignCenter, 2)) ;


		   tT4.addCell(PdfExportServer.createCell(bfChinese, "出租人（签字）： " , fontDefault, paddingDefault, borderStart3,alignCenter, 4)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "日期： " , fontDefault, paddingDefault, borderStart3,alignCenter, 6)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "承租人（签字）： " , fontDefault, paddingDefault, borderEnd2,alignCenter, 4)) ;
		   tT4.addCell(PdfExportServer.createCell(bfChinese, "日期： " , fontDefault, paddingDefault, borderEnd2,alignCenter, 6)) ;

		   document.add(tT4);
		} catch (Exception e) {
		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_405_NAME,"导出起租通知书，文件处理错误！");
	}finally {
	        try {
	            document.close();
	        } catch (Exception e) {
	            //可能之前已经关闭过了
	        }
			}
		}
	}

	@Override
	public PrjPrdPaySchMVO searchSettleData(Long paySchId, Date applyDate, Integer payPd) throws BaseException {
		if (StringUtils.isEmpty(paySchId)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "请选择要结清的支付表信息！");
		}
		PrjPrdPaySchMVO prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(this.prjPrdPaySchMApiService.searchSettleData(paySchId, applyDate, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), payPd));
		if (applyDate != null) {
			// 日期不为null，则代表是请求结清预览页面的数据，计算IRR和结清优惠金额1
			calcIrrAndDiscountAmt(prjPrdPaySch);
		}
		getTotalValue(prjPrdPaySch);
		return prjPrdPaySch;
	}

	@Override
	public  List<SysDictionaryVO> getSettFeeTypList() throws BaseException {
		//费用对应关系
		List<SysDictionaryDTO>  allList =   this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_ALL_TYP_CD);//所有费用类型
		List<SysDictionaryDTO> settList =  this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_SETT_TYP_CD);//结清类型
		for (SysDictionaryDTO set : settList) {
			for (SysDictionaryDTO all : allList) {
				if(set.getCode().equals(all.getCode())){
					set.setCodeAttr1(all.getCodeAttr1());
				}
			}
		}
		return SysDictionaryVOTransform.toVOList(settList);
	}

	/******************************************************
     * 获取发起流程对象
     * @param businessType:业务类型(FlowConstant.FLOW_BUSINESS_TYP_SETTLE)
     * @param modelTyp:流程业务分类
     * 			           正常结清:FlowConstant.FLOW_MODEL_TYP_SETTLE_NORMAL
     * 				   提前结清:FlowConstant.FLOW_MODEL_TYP_SETTLE_ADVANCE
     * 				   强制结清:FlowConstant.FLOW_MODEL_TYP_SETTLE_FORCE
     * @return
     * @throws BaseException
     *****************************************************/
    private FlowStartParamsDTO getFlowStartParams(String businessType,String modelTyp)throws BaseException{
    	if(StringUtils.isEmpty(modelTyp)){
    		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "流程业务分类不能为空");
    	}
        FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
        //流程定义KEY和流程定义ID不定义  流程发起的时候会根据模块类型查找唯一流程去发起
        //flowStartParamsDTO.setProcDefKey("");
        //flowStartParamsDTO.setProcDefId("");
        flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
        flowStartParamsDTO.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
        flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
        String orgCd = CurrentThreadContext.getCurrentOrgCd();
        String buOrgCd = CurrentThreadContext.getCurrentBuOrgCd();
        // 提前结清和正常结清中若发起人组织架构命中迁移的组织架构，则发起优车事业部流程
        if (FlowConstant.FLOW_MODEL_TYP_SETTLE_NORMAL.equals(modelTyp) || FlowConstant.FLOW_MODEL_TYP_SETTLE_ADVANCE.equals(modelTyp)) {
            boolean ycOrgCheck = this.projectApiService.isYcOrgCheck(orgCd);
            if (true == ycOrgCheck) {
                orgCd = PrjBscInfoConstant.CODE_BU_ORG_CD_YC;
                buOrgCd = PrjBscInfoConstant.CODE_BU_ORG_CD_YC;
            }
        }
        flowStartParamsDTO.setOrgCd(orgCd);
        flowStartParamsDTO.setBuOrgCd(buOrgCd);

        flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
        flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
        flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
        flowStartParamsDTO.setBusinessType(businessType);//TODO 确认用不用
        flowStartParamsDTO.setModelTyp(modelTyp);//需要和流程配置中的模块类型匹配
        return flowStartParamsDTO;
    }

	@Override
	public DataResultVO addFileAndApplyNormalSett(PrjPrdPaySchMVO pay) throws BaseException {
		DataResultVO resultVO = new DataResultVO();
		if (null == pay) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表结清申请书不能为空！");
		}
		boolean bol = settlementFileService.isUploadStlApplication(String.valueOf(pay.getId()));
		if (!bol) {
			throw new BaseException("请上传结清申请书！");
		}

		PrjPrdPaySchMDTO dto = PrjPrdPaySchMVOTransform.toDTO(pay);
		dto.setSysCd(CurrentThreadContext.getCurrentSysCd());
		dto.setOrgCd(CurrentThreadContext.getCurrentOrgCd());

		FlowStartParamsDTO flowStartParamsDTO = null;
		DataResultDTO resultdto = null;
		// REQ-3199 资管结清添加参数：0-单台结清 1-全部结清
		if (StringUtils.isNotEmpty(pay.getIsAllStl())) {
			// 资管结清
			flowStartParamsDTO = this.getFlowStartParams(FlowConstant.FLOW_BUSINESS_TYP_SETTLE, SettleConstant.FLOW_MODEL_TYP_ZG_SETT);
			Map<String, Object> startParams = Maps.newHashMap();
			startParams.put("isAllStl", pay.getIsAllStl());
			flowStartParamsDTO.setStartParams(startParams);
			dto.setFlowStartParamsDTO(flowStartParamsDTO);
			dto.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			dto.setCrtUsrName(CurrentThreadContext.getCurrentUserName());
			resultdto = this.prjSettleOfFinaInstApiService.addFileAndApplyZGNormalSettle(dto);
		} else {
			flowStartParamsDTO = this.getFlowStartParams(FlowConstant.FLOW_BUSINESS_TYP_SETTLE, FlowConstant.FLOW_MODEL_TYP_SETTLE_NORMAL);
			dto.setFlowStartParamsDTO(flowStartParamsDTO);
			resultdto = this.prjPrdPaySchMApiService.addFileAndApplyNormalSett(dto);
		}
		resultVO.setData(resultdto.getData());
		resultVO.setInfo(resultdto.getInfo());
		return resultVO;
	}

	@Override
	public DataResultVO addFileAndPreNormalSett(PrjPrdPaySchMVO pay) throws BaseException {
		DataResultVO resultVO = new DataResultVO();
		if (null == pay) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表结清申请书不能为空！");
		}
		boolean bol = settlementFileService.isUploadStlApplication(String.valueOf(pay.getId()));
		if (!bol) {
			throw new BaseException("请上传结清申请书！");
		}

		PrjPrdPaySchMDTO dto = PrjPrdPaySchMVOTransform.toDTO(pay);
		dto.setSysCd(CurrentThreadContext.getCurrentSysCd());
		dto.setOrgCd(CurrentThreadContext.getCurrentOrgCd());

		FlowStartParamsDTO flowStartParamsDTO = null;
		DataResultDTO resultdto = null;
		// REQ-3199 资管结清添加参数：0-单台结清 1-全部结清
		if (StringUtils.isNotEmpty(pay.getIsAllStl())) {
			// 资管结清
			flowStartParamsDTO = this.getFlowStartParams(FlowConstant.FLOW_BUSINESS_TYP_SETTLE, SettleConstant.FLOW_MODEL_TYP_ZG_SETT);
			Map<String, Object> startParams = Maps.newHashMap();
			startParams.put("isAllStl", pay.getIsAllStl());
			flowStartParamsDTO.setStartParams(startParams);
			dto.setFlowStartParamsDTO(flowStartParamsDTO);
			dto.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			dto.setCrtUsrName(CurrentThreadContext.getCurrentUserName());
			resultdto = this.prjSettleOfFinaInstApiService.addFileAndApplyZGPreSettle(dto);
		} else {
			flowStartParamsDTO = this.getFlowStartParams(FlowConstant.FLOW_BUSINESS_TYP_SETTLE, FlowConstant.FLOW_MODEL_TYP_SETTLE_ADVANCE);
			dto.setFlowStartParamsDTO(flowStartParamsDTO);
            dto.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            dto.setMdfTm(new Date());
			resultdto = this.prjPrdPaySchMApiService.addFileAndPreNormalSett(dto);
		}
		resultVO.setData(resultdto.getData());
		resultVO.setInfo(resultdto.getInfo());
		return resultVO;
	}
	/**
	 * 提前结清
	 */
	public PrjPrdPaySchMVO searchPreSettleData(Long paySchId, Date date, Integer settPayPd) throws BaseException {
		if (null == paySchId) return new PrjPrdPaySchMVO();

		PrjPrdPaySchMVO prjPrdPaySch = null;
		try {
			prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(this.prjPrdPaySchMApiService.searchPreSettleData(paySchId, date, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), settPayPd));

			if (date != null) {
				// 日期不为null，则代表是请求结清预览页面的数据，计算IRR和结清优惠金额1
				calcIrrAndDiscountAmt(prjPrdPaySch);
			}

			getTotalValue(prjPrdPaySch);
		} catch (BaseException ex) {
			BaseLogUtils.error(logger, "searchPreSettleData", "结清数据查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
			throw ex;
		} catch (Exception ex) {
			BaseLogUtils.error(logger, "searchPreSettleData", "结清数据查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
			throw ex;
		}
		return prjPrdPaySch;
	}

	/**
	 * 计算IRR和结清优惠金额1
	 * @param schMVO
	 * @throws BaseException
	 */
	private void calcIrrAndDiscountAmt(PrjPrdPaySchMVO schMVO) throws BaseException {
		Map<String, Double> irrMap = prjPrdPaySchMApiService.getCalcStlCstIRRAndDiscountForAnyPaySchId(schMVO.getId(), schMVO.getStartLsPd(),
				schMVO.getTotalSettAmt().longValue(), schMVO.getApplyDt());
		Double irr = irrMap.get("irr");
		Double discountAmtIRR = irrMap.get("discountAmtIRR");
		schMVO.setTotalSettAmt(schMVO.getTotalSettAmt() - discountAmtIRR);
		schMVO.setFinalPayAmt(schMVO.getTotalSettAmt());
		schMVO.setCstStlIrr(irr);
		schMVO.setDiscountAmt1(discountAmtIRR);
	}

	@Override
	public PrjPrdPaySchMVO getPrjPrdPaySettPayPd(Long paySchId, String sett, Date settDate) throws BaseException {
		if(null==paySchId) return new PrjPrdPaySchMVO();
		return PrjPrdPaySchMVOTransform.toVO(this.prjPrdPaySchMApiService.getPrjPrdPaySettPayPd(paySchId,sett,settDate));
	}

	@Override
	public int prjPrdPayApplySettFlag(Long paySchId, String sett) throws BaseException {
		if (null == paySchId) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表ID不能为空!");
		}
		if (!(PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_NORMAL.equals(sett)
				|| PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_PRE.equals(sett))) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "结清类型标识错误!");
		}

		// 注意：paySchId为我司支付表ID
		List<PrjPrdPaySchMDTO> paySchMDTOList = prjPrdPaySchMApiService.selectEnabledListByPaySchId(paySchId);
		if (CollectionUtils.isEmpty(paySchMDTOList)) {
			throw new BaseException("未查询到启用的支付表信息！");
		}
		PrjPrdPaySchMDTO paySchMDTO = paySchMDTOList.get(0);
		if (paySchMDTO == null) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "未找到启用的支付表！");
		}
		if (!PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_ZF.equals(paySchMDTO.getPaySchTypCd())
				&& paySchMDTO.getIsSqBiz() == BaseConstant.IS_YESNO_YES) {
			// 走我司结清流程发起条件校验
			checkOurSettFLowCondition(sett, paySchMDTO);
			return 1;
		} else if (PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_ZF.equals(paySchMDTO.getPaySchTypCd())) {
			// 走资管结清流程发起条件校验
			// 转换结清类型标识
			String settleType = PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_NORMAL.equals(sett) ? "1" : "2";
			prjSettleOfFinaInstApiService.checkApplyConstraints(paySchId, null, settleType);
			return 2;
		} else {
			throw new BaseException("该支付表没有符合条件的结清流程！");
		}
	}

	/**
	 * 校验我司结清流程发起条件
	 * @param paySchId
	 * @param sett
	 * @param paySchMDTO
	 * @return
	 * @throws BaseException
	 */
	private boolean checkOurSettFLowCondition(String sett, PrjPrdPaySchMDTO paySchMDTO) throws BaseException {
		String settleType = PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_NORMAL.equals(sett) ?
				SettleConstant.CODE_SETT_TYPE_NORMAL : SettleConstant.CODE_SETT_TYPE_ADVANCE;
		prjPrdPaySchMApiService.checkOurSettleStartRule(paySchMDTO.getId(), settleType);
		return true;
	}

	/**
	 * 导出excel数据
	 */
	public void exportPrjPrdPaySchExcelData(Long id, ByteArrayOutputStream out) throws BaseException {
		try {
		PrjPrdPaySchMVO schM = 	this.selectPrjPrdPaySchMAndDetailById(id);
		String lsCnNo ="";
		String cstNm = "";
		if(null!=schM){
			if(null!=schM.getPrjId()){
				PrjBscInfoVO prjBsc = this.prjBscInfoService.selectById(schM.getPrjId());
				lsCnNo = prjBsc.getLsCntNo()==null?"":prjBsc.getLsCntNo();
			}
			if(null!=schM.getCstId()){
				CstBscInfoVO cst = this.cstBscInfoService.selectDetailById(schM.getCstId());
				if(null!=cst){
					cstNm = cst.getCstNm()==null?"":cst.getCstNm();
				}
			}
	}


		  PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
		   dtlQc.setPaySchId(id);
		   List<PrjPrdDtlVO> dtlList =   this.prjPrdDtlService.selectList(dtlQc);
		   PrjPrdDtlVO dtl = null;
		   double price = 0;
		   double  rsrvPc = 0d;
		   //String machNo = "";
		   String priceStr ="";
		   if(CollectionUtils.isNotEmpty(dtlList)){
			   dtl = dtlList.get(0);
			   if(null!=dtl.getPrjPrdId()){
				   PrjPrdBscInfoVO prjPrd =    this.prjPrdBscInfoService.getPrjPrdBscInfoById(dtl.getPrjPrdId());
				   if(null!=prjPrd){
					   price = prjPrd.getGuidePc()==null?0:prjPrd.getGuidePc();
					   rsrvPc = prjPrd.getRsrvPc()==null?0:prjPrd.getRsrvPc();
					   BigDecimal bd = new BigDecimal(price);
					    priceStr = bd.toPlainString();
				   }
			   }
		   }else{
			   dtl = new PrjPrdDtlVO();
		   }
		   List<PrjPrdPaySchDVO> detailList = schM.getFeeDetailList();
		   PrjBscInfoVO prjBscInfoVO =  this.prjBscInfoService.selectById(schM.getPrjId());
		   //查询日罚息率
		   String punish = "";
		  List<SysDictionaryDTO> list =   this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getBuOrgCd(), CapitalConstant.CODE_CAP_OVERDUE_RATE_CD);
		   if(CollectionUtils.isNotEmpty(list)){
			   punish = list.get(0).getCode();
		   }

	        HSSFWorkbook wb = new HSSFWorkbook();
	        HSSFFont headfont = wb.createFont();
	        headfont.setFontName("宋体");
	        headfont.setFontHeightInPoints((short) 22);// 字体大小
	        HSSFCellStyle headstyle = wb.createCellStyle();
	        headstyle.setFont(headfont);
	        headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
	        headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
	        headstyle.setLocked(true);

	        HSSFSheet sheet = wb.createSheet("支付表");
	        HSSFCellStyle style = wb.createCellStyle();
	        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
	        /*style.setBorderBottom((short)1);
	        style.setBorderLeft((short)1);
	        style.setBorderRight((short)1);
	        style.setBorderTop((short)1);*/
	        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
	        // 普通单元格样式（中文）
	        HSSFFont font2 = wb.createFont();
	        font2.setFontName("宋体");
	        font2.setFontHeightInPoints((short) 12);
	        style.setFont(font2);

	        HSSFRow titleRow = sheet.createRow((int) 0);
	        HSSFCell titleCell = titleRow.createCell(0);
	        titleCell.setCellValue("支付表");
	        titleCell.setCellStyle(headstyle);
	        HSSFRow row = sheet.createRow((int) 1);
	        HSSFCell cell = row.createCell(0);
	        cell.setCellValue("支付表号");
	        cell.setCellStyle(style);


	        cell = row.createCell(1);
	        cell.setCellValue("融资合同");
	        cell.setCellStyle(style);


	        cell = row.createCell(2);
	        cell.setCellValue("承租人");
	        cell.setCellStyle(style);


	        cell = row.createCell(3);
	        cell.setCellValue("租赁物总价值");
	        cell.setCellStyle(style);


	        cell = row.createCell(4);
	        cell.setCellValue("大写");
	        cell.setCellStyle(style);


	        cell = row.createCell(5);
	        cell.setCellValue("支付方式");
	        cell.setCellStyle(style);


	        HSSFRow row1 = sheet.createRow((int) 2);
	        cell = row1.createCell(0);
	        cell.setCellValue(schM.getPaySchNo());
	        cell.setCellStyle(style);

	         cell = row1.createCell(1);
	        cell.setCellValue(lsCnNo);
	        cell.setCellStyle(style);

	         cell = row1.createCell(2);
	        cell.setCellValue(cstNm);
	        cell.setCellStyle(style);

	        cell = row1.createCell(3);
	        cell.setCellValue(schM.getTotLsItmAmt());
	        cell.setCellStyle(style);

	         cell = row1.createCell(4);
	        cell.setCellValue(ProjectUtils.hangeToBig(schM.getTotLsItmAmt()));
	        cell.setCellStyle(style);

	        cell = row1.createCell(5);
	        cell.setCellValue(schM.getPayWayCdNm());
	        cell.setCellStyle(style);


	        Integer period = ProjectUtils.getRentPeriod(schM.getLsPd().intValue(), Integer.valueOf(schM.getLsPdUntCd()));
	        HSSFRow payRow = sheet.createRow((int) 3);
	        HSSFCell paycell = payRow.createCell(0);
	        paycell.setCellValue("租赁期数");
	        paycell.setCellStyle(style);


	        paycell = payRow.createCell(1);
	        paycell.setCellValue("租赁周期（月）");
	        paycell.setCellStyle(style);


	        paycell = payRow.createCell(2);
	        paycell.setCellValue("日罚息率");
	        paycell.setCellStyle(style);


	        paycell = payRow.createCell(3);
	        paycell.setCellValue("租赁年利率");
	        paycell.setCellStyle(style);


	        paycell = payRow.createCell(4);
	        paycell.setCellValue("利率上浮比例");
	        paycell.setCellStyle(style);


	        paycell = payRow.createCell(5);
	        paycell.setCellValue("实际租赁物价值");
	        paycell.setCellStyle(style);


	        paycell = payRow.createCell(6);
	        paycell.setCellValue("起租日期");
	        paycell.setCellStyle(style);


	        HSSFRow payRow1 = sheet.createRow((int) 4);

	        paycell = payRow1.createCell(0);
	        paycell.setCellValue(schM.getLsPd().intValue());
	        paycell.setCellStyle(style);

	         paycell = payRow1.createCell(1);
	        paycell.setCellValue(period);
	        paycell.setCellStyle(style);

	         paycell = payRow1.createCell(2);
	        paycell.setCellValue(punish+"%");
	        paycell.setCellStyle(style);

	          paycell = payRow1.createCell(3);
	        paycell.setCellValue(schM.getAnnIntRatePct()+"%");
	        paycell.setCellStyle(style);

	        paycell = payRow1.createCell(4);
	        paycell.setCellValue(null==schM.getIntRateRsPct()?"":schM.getIntRateRsPct()+"%");
	        paycell.setCellStyle(style);

	        paycell = payRow1.createCell(5);
	        paycell.setCellValue(schM.getActLsAmt());
	        paycell.setCellStyle(style);

	        paycell = payRow1.createCell(6);
	        paycell.setCellValue(DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD));
	        paycell.setCellStyle(style);

	        //产品信息
	        HSSFRow prdRow = sheet.createRow((int) 5);
	        HSSFCell prdcell = prdRow.createCell(0);
	        prdcell.setCellValue("租赁物清单");
	        prdcell.setCellStyle(style);

	        prdcell = prdRow.createCell(1);
	        prdcell.setCellValue("租赁物名称");
	        prdcell.setCellStyle(style);
	        prdcell = prdRow.createCell(2);
	        prdcell.setCellValue("型号");
	        prdcell.setCellStyle(style);

	      /*  prdcell = row.createCell(3);
	        prdcell.setCellValue("整机编号");
	        prdcell.setCellStyle(style);  */

	        prdcell = prdRow.createCell(3);
	        prdcell.setCellValue("单价");
	        prdcell.setCellStyle(style);

	        prdcell = prdRow.createCell(4);
	        prdcell.setCellValue("数量");
	        prdcell.setCellStyle(style);
	        prdcell = prdRow.createCell(5);
	        prdcell.setCellValue("留购价");
	        prdcell.setCellStyle(style);
	        //产品信息
	        HSSFRow prdValueRow = sheet.createRow((int) 6);
	        HSSFCell prdValueCell = prdValueRow.createCell(0);
	        prdValueCell.setCellValue(null==dtl.getPrdNm()?"":dtl.getPrdNm());
	        prdValueCell.setCellStyle(style);

	        prdValueCell = prdValueRow.createCell(1);
	        prdValueCell.setCellValue(null==dtl.getPrdMdl()?"":dtl.getPrdMdl());
	        prdValueCell.setCellStyle(style);

	        prdValueCell = prdValueRow.createCell(2);
	        prdValueCell.setCellValue(priceStr);
	        prdValueCell.setCellStyle(style);

	        prdValueCell = prdValueRow.createCell(3);
	        prdValueCell.setCellValue(dtl.getPrdQty());
	        prdValueCell.setCellStyle(style);

	        prdValueCell = prdValueRow.createCell(4);
	        prdValueCell.setCellValue(rsrvPc);
	        prdValueCell.setCellStyle(style);
	        //费用项列表
	        HSSFRow feeRow = sheet.createRow((int) 7);
	        HSSFCell feeCell = feeRow.createCell(1);
	        feeCell.setCellValue("费用名称");
	        feeCell.setCellStyle(style);

	        feeCell = feeRow.createCell(2);
	        feeCell.setCellValue("费用比例");
	        feeCell.setCellStyle(style);
	        feeCell = feeRow.createCell(3);
	        feeCell.setCellValue("费用金额");
	        feeCell.setCellStyle(style);

	        feeCell = feeRow.createCell(4);
	        feeCell.setCellValue("备注");
	        feeCell.setCellStyle(style);
	      for (int i = 0; i < schM.getFeeDetailList().size(); i++)
	        {
		        HSSFRow   schRow = sheet.createRow((int) i + 8);
	            PrjPrdPaySchDVO feeVo = schM.getFeeDetailList().get(i);
	            schRow.createCell(1).setCellValue(null==feeVo.getFeeTypCdNm()?"":feeVo.getFeeTypCdNm());
	            HSSFCell  schCell = schRow.createCell(1);
	            schCell.setCellValue(null==feeVo.getFeeTypCdNm()?"":feeVo.getFeeTypCdNm());
	            schCell.setCellStyle(style);
	            schCell = schRow.createCell(2);
	            schCell.setCellValue(null==feeVo.getFeePct()?0:feeVo.getFeePct());
	            schCell.setCellStyle(style);
	            schCell = schRow.createCell(3);
	            schCell.setCellValue(null==feeVo.getFeeAmt()?0:feeVo.getFeeAmt());
	            schCell.setCellStyle(style);
	          //保证金转出备注
	            String remarkForFee = "";
	            CapFeeOutLogQueryCondition condition = new CapFeeOutLogQueryCondition();
	            condition.setPaySchId(feeVo.getPaySchId());
	            condition.setPaySchDId(feeVo.getId());
	            condition.setFeeTypCd(feeVo.getFeeTypCd());
	            List<CapFeeOutLogVO> CapFeeOutLogList = this.capFeeOutLogService.searchList(condition);
	            if(CollectionUtils.isNotEmpty(CapFeeOutLogList)){
	            	int j=0;
	            	for(CapFeeOutLogVO capFeeOutLogVO :CapFeeOutLogList){
	            		j++;
	            		remarkForFee += capFeeOutLogVO.getCrtUsrNm()==null?"":capFeeOutLogVO.getCrtUsrNm()+"-->";
	            		remarkForFee += capFeeOutLogVO.getCrtTm()==null?"":DateUtils.formatDateToString(capFeeOutLogVO.getCrtTm(), "yyyy-MM-dd hh:mm:ss")+"-->";
	            		remarkForFee += capFeeOutLogVO.getHandleWayCdNm()==null?"":capFeeOutLogVO.getHandleWayCdNm();
	            		remarkForFee += capFeeOutLogVO.getOutAmt()==null?"":BigDecimal.valueOf(capFeeOutLogVO.getOutAmt()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP) + "元-->";
	            		remarkForFee += capFeeOutLogVO.getOutRem()==null?"":capFeeOutLogVO.getOutRem();
	            		if(j<CapFeeOutLogList.size()){
	            			remarkForFee += "---";
	            		}
	            	}
	            }
	            schCell = schRow.createCell(4);
	            schCell.setCellValue(remarkForFee);
	            schCell.setCellStyle(style);
	            Region region = new Region(i + 8, (short)4, i + 8, (short)6);
		        sheet.addMergedRegion(region);
	            //schRow.createCell(2).setCellValue(null==feeVo.getFeePct()?0:feeVo.getFeePct());
	            //schRow.createCell(3).setCellValue(null==feeVo.getFeeAmt()?0:feeVo.getFeeAmt());
	        }
	        int startRow = schM.getFeeDetailList().size()+9;
	        //费用项列表
	        HSSFRow prjPayRow = sheet.createRow((int) startRow);
	        HSSFCell prjPayCell = prjPayRow.createCell(0);
	        prjPayCell.setCellValue("期次");
	        prjPayCell.setCellStyle(style);

	        prjPayCell = prjPayRow.createCell(1);
	        prjPayCell.setCellValue("支付时间");
	        prjPayCell.setCellStyle(style);

	        prjPayCell = prjPayRow.createCell(2);
	        prjPayCell.setCellValue("租金");
	        prjPayCell.setCellStyle(style);

	        prjPayCell = prjPayRow.createCell(3);
	        prjPayCell.setCellValue("本金");
	        prjPayCell.setCellStyle(style);

	        prjPayCell = prjPayRow.createCell(4);
	        prjPayCell.setCellValue("利息");
	        prjPayCell.setCellStyle(style);

	        prjPayCell = prjPayRow.createCell(5);
	        prjPayCell.setCellValue("剩余本金");
	        prjPayCell.setCellStyle(style);

	        prjPayCell = prjPayRow.createCell(6);
	        prjPayCell.setCellValue("备注");
	        prjPayCell.setCellStyle(style);

	        for(int i=0;i<schM.getPrjPrdPayDetailList().size();i++)
			   {
				PrjPrdPrpsFeeDetailVO payVo = schM.getPrjPrdPayDetailList().get(i);
	            row = sheet.createRow((int) i + startRow+1);
	            HSSFCell  payCell = row.createCell(0);
	            payCell.setCellValue(payVo.getPayPd());
	            payCell.setCellStyle(style);

	            payCell = row.createCell(1);
	            payCell.setCellValue(DateUtils.formatDateToString(payVo.getPayDt(), DateUtils.YYYY_MM_DD));
	            payCell.setCellStyle(style);

	            payCell = row.createCell(2);
	            payCell.setCellValue(payVo.getRntAmt());
	            payCell.setCellStyle(style);
	            //row.createCell(0).setCellValue(payVo.getPayPd());
	            //row.createCell(1).setCellValue(DateUtils.formatDateToString(payVo.getPayDt(), DateUtils.YYYY_MM_DD));
	            //row.createCell(2).setCellValue(payVo.getRntAmt());

	            payCell = row.createCell(3);
	            payCell.setCellValue(payVo.getPrinAmt());
	            payCell.setCellStyle(style);

	            payCell = row.createCell(4);
	            payCell.setCellValue(payVo.getIntAmt());
	            payCell.setCellStyle(style);

	            payCell = row.createCell(5);
	            payCell.setCellValue(payVo.getRemPrinAmt());
	            payCell.setCellStyle(style);

	            payCell = row.createCell(6);
	            payCell.setCellValue("");
	            payCell.setCellStyle(style);

	            /*row.createCell(3).setCellValue(payVo.getPrinAmt());
	            row.createCell(4).setCellValue(payVo.getIntAmt());
	            row.createCell(5).setCellValue(payVo.getRemPrinAmt());
	            row.createCell(6).setCellValue(""); */
	        }
	        int rowNum = startRow+1+schM.getPrjPrdPayDetailList().size();
	        //费用项列表
	        HSSFRow totalRow = sheet.createRow((int) rowNum);
	        HSSFCell totalCell = totalRow.createCell(0);

	        totalCell.setCellValue("金额合计");
	        totalCell.setCellStyle(style);

	        totalCell = totalRow.createCell(2);
	        totalCell.setCellValue(schM.getTotalRntAmt());
	        totalCell.setCellStyle(style);

	        totalCell = totalRow.createCell(3);
	        totalCell.setCellValue(schM.getTotalPrinAmt());
	        totalCell.setCellStyle(style);

	        totalCell = totalRow.createCell(4);
	        totalCell.setCellValue(schM.getTotalIntAmt());
	        totalCell.setCellStyle(style);

	        HSSFRow cstRow1 = sheet.createRow((int) rowNum+1);
	        HSSFCell cstCell1 = cstRow1.createCell(2);
	        cstCell1.setCellValue("出租人（签字）:");
	        cstCell1.setCellStyle(style);

	        cstCell1 = cstRow1.createCell(4);
	        cstCell1.setCellValue("日期:");
	        cstCell1.setCellStyle(style);

	        HSSFRow cstRow2 = sheet.createRow((int) rowNum+2);
	        HSSFCell cstCell2 = cstRow2.createCell(2);
	        cstCell2.setCellValue("乘租人（签字）:");
	        cstCell2.setCellStyle(style);

	        cstCell2 = cstRow2.createCell(4);
	        cstCell2.setCellValue("日期:");
	        cstCell2.setCellStyle(style);
	        sheet.autoSizeColumn((short)0); //调整第一列宽度
	        sheet.autoSizeColumn((short)1); //调整第二列宽度
	        sheet.autoSizeColumn((short)2); //调整第三列宽度
	        sheet.autoSizeColumn((short)3); //调整第四列宽度
	        sheet.autoSizeColumn((short)4); //调整第五列宽度
	        sheet.autoSizeColumn((short)5); //调整第六列宽度
	        sheet.autoSizeColumn((short)6); //调整第七列宽度
	        sheet.autoSizeColumn((short)7); //调整第八列宽度
	        sheet.autoSizeColumn((short)8); //调整第八列宽度
	        sheet.autoSizeColumn((short)9); //调整第八列宽度
	        sheet.autoSizeColumn((short)10); //调整第八列宽度
	        Region region1 = new Region(0, (short)0, 0, (short)10);
	        Region region2 = new Region(5, (short)0, 6, (short)0);
	        sheet.addMergedRegion(region1);
	        sheet.addMergedRegion(region2);
				wb.write(out);
			} catch (IOException e) {
				// TODO Auto-generated catch block
			BaseLogUtils.error(logger, "-", "异常", e);
			}
  }

	@Override
	public Pager selectPrjPrdPaySchMDelMgrListPage(Pager page) throws BaseException {
		if(null==page){
			return new Pager();
		}
		return this.prjPrdPaySchMApiService.selectPrjPrdPaySchMDelMgrListPage(page);
	}

	@Override
	public PrjPrdPaySchMVO searchCarPreSettleData(Long paySchId, Date date, Integer payPd) throws BaseException {
		if (null == paySchId) {
			return new PrjPrdPaySchMVO();
		}
		PrjPrdPaySchMVO prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(prjPrdPaySchMApiService.searchCarPreSettleData(paySchId, date, payPd, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd()));

		if (date != null) {
			// 日期不为null，则代表是请求结清预览页面的数据，计算IRR和结清优惠金额1
			calcIrrAndDiscountAmt(prjPrdPaySch);
		}

		return getTotalValue(prjPrdPaySch);
	}

	@Override
	public PrjPrdPaySchMVO searchSettleDataForFlow(Long paySchId, Date applyDate, Integer payPd) {
		PrjPrdPaySchMVO prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(prjPrdPaySchMApiService.searchSettleDataForFlow(paySchId, applyDate, payPd));
		return	getTotalValue(prjPrdPaySch);
	}

	/**
	 * 修改工行账户
	 * @author jiangzg 2017-10-18 17:54:14
	 * @param entity
	 * @return
	 */
	@Override
	public boolean modifyCrCardNo(PrjPrdPaySchMVO entity) throws BaseException{
		if(null == entity) return false;
		return this.prjPrdPaySchMApiService.modifyCrCardNo(PrjPrdPaySchMVOTransform.toDTO(entity));
	}

	@Override
	public PrjPrdPaySchMVO searchCarNormalSettleData(Long paySchId, Date applyDate, Integer settPayPd) throws BaseException {
		PrjPrdPaySchMVO prjPrdPaySch =	PrjPrdPaySchMVOTransform.toVO(this.prjPrdPaySchMApiService.searchCarNormalSettleData(paySchId,applyDate,settPayPd,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd()));

		if (applyDate != null) {
			// 日期不为null，则代表是请求结清预览页面的数据，计算IRR和结清优惠金额1
			calcIrrAndDiscountAmt(prjPrdPaySch);
		}

		return 	getTotalValue(prjPrdPaySch);
	}

	@Override
	public DataResultVO addFileAndApplyCarNormalSett(PrjPrdPaySchMVO pay) throws BaseException {

		DataResultVO resultVO = new  DataResultVO();
		if(null==pay){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"支付表结清申请书不能为空！");
		}

		boolean bol = settlementFileService.isUploadStlApplication(String.valueOf(pay.getId()));
		if (!bol) {
			throw new BaseException("请上传结清申请书！");
		}

		PrjPrdPaySchMDTO dto = PrjPrdPaySchMVOTransform.toDTO(pay);
		dto.setSysCd(CurrentThreadContext.getCurrentSysCd());
		dto.setOrgCd(CurrentThreadContext.getCurrentOrgCd());

		FlowStartParamsDTO flowStartParamsDTO = this.getFlowStartParams(FlowConstant.FLOW_BUSINESS_TYP_SETTLE,FlowConstant.FLOW_MODEL_TYP_SETTLE_NORMAL);
		dto.setFlowStartParamsDTO(flowStartParamsDTO);
		DataResultDTO resultdto = this.prjPrdPaySchMApiService.addFileAndApplyCarNormalSett(dto);
		resultVO.setData(resultdto.getData());
		resultVO.setInfo(resultdto.getInfo());
		return resultVO;
	}

	@Override
	public PrjPrdPaySchMVO searchCarNormalSettleDataForFlow(Long paySchId, Date applyDate, Integer payPd)
			throws BaseException {
		PrjPrdPaySchMVO prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(prjPrdPaySchMApiService.searchCarNormalSettleDataForFlow(paySchId, applyDate, payPd));
		return	getTotalValue(prjPrdPaySch);
	}

	@Override
	public boolean checkNormalPaySchSettAmt(Long paySchId, Long setAmt) throws BaseException {
		return prjPrdPaySchMApiService.checkNormalPaySchSettAmt(paySchId,setAmt);
	}

	@Override
	public boolean checkPrePaySchSettAmt(Long paySchId, Long setAmt) throws BaseException {
		return prjPrdPaySchMApiService.checkPrePaySchSettAmt(paySchId,setAmt);
	}

	@Override
	public PrjPrdPaySchMVO searchPrjPrdSchTMSettleDataForQCJR(Long paySchId) throws BaseException {
		PrjPrdPaySchMVO prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(prjPrdPaySchMApiService.searchPrjPrdSchTMSettleDataForQCJR(paySchId));
		getTotalValue(prjPrdPaySch);
		//合计本金、合计利息、合计剩余本金、合计租金
		 double  totalRntAmt = 0d;//合计租金
		 double  totalPrinAmt = 0d;//合计本金
		 double  totalIntAmt = 0d;//合计利息
		 double totalRemPrinAmt = 0d;//合计剩余本金
		 double firstPayAmt = 0d;//首付款
		 List<PrjPrdPrpsFeeDetailVO> prjPrdPayDetailList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
		 Map<Integer,PrjPrdPrpsFeeDetailVO> prdPayMap = new HashMap<Integer,PrjPrdPrpsFeeDetailVO>();
		 PrjPrdPaySchTDQC tdQc = new PrjPrdPaySchTDQC();
    	 tdQc.setPaySchId(Long.valueOf(paySchId));
    	 List<PrjPrdPaySchTDVO> dtList = this.prjPrdPaySchTDService.searchList(tdQc);
    		if(CollectionUtils.isNotEmpty(dtList)){
				for (PrjPrdPaySchTDVO detail : dtList) {
					   if(detail.getPayPd().intValue()!=PrjQuatPrpsConstant.CODE_PRJ_PRD_FEE_PD){
						if(!prdPayMap.containsKey(detail.getPayPd().intValue())){
							PrjPrdPrpsFeeDetailVO feeDetail = new PrjPrdPrpsFeeDetailVO();
							feeDetail.setPayPd(detail.getPayPd().intValue());
							feeDetail.setIsModify(detail.getIsModify());
							feeDetail.setPayDt(detail.getPayDt());
							if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)){
								//租金
								totalRntAmt = DecimalUtils.add(totalRntAmt, detail.getFeeAmt());
								feeDetail.setRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
							}
							if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)){
								//	利息
								totalIntAmt = DecimalUtils.add(totalIntAmt, detail.getFeeAmt());
								feeDetail.setIntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
							}
							if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)){
								//本金
								totalPrinAmt = DecimalUtils.add(totalPrinAmt, detail.getFeeAmt());
								feeDetail.setPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
							}
							if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_REMPRIN_PRICE)){
								//剩余本金
								totalRemPrinAmt = DecimalUtils.add(totalRemPrinAmt, detail.getFeeAmt());
								feeDetail.setRemPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
							}
							prdPayMap.put(detail.getPayPd().intValue(), feeDetail);
						}else{
							if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)){
								//租金
								totalRntAmt = DecimalUtils.add(totalRntAmt, detail.getFeeAmt());
								prdPayMap.get(detail.getPayPd().intValue()).setRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
							}
							if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)){
								//	利息
								totalIntAmt = DecimalUtils.add(totalIntAmt, detail.getFeeAmt());
								prdPayMap.get(detail.getPayPd().intValue()).setIntAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
							}
							if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)){
								//本金
								totalPrinAmt = DecimalUtils.add(totalPrinAmt, detail.getFeeAmt());
								prdPayMap.get(detail.getPayPd().intValue()).setPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
							}
							if(detail.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_REMPRIN_PRICE)){
								//剩余本金
								totalRemPrinAmt = DecimalUtils.add(totalRemPrinAmt, detail.getFeeAmt());
								prdPayMap.get(detail.getPayPd().intValue()).setRemPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf((detail.getFeeAmt())).longValue()));
							}
						}

					   }
				}
			}
			 for (Integer key : prdPayMap.keySet()) {
				 	prjPrdPayDetailList.add(prdPayMap.get(key));
				  }
			 prjPrdPaySch.setTotalPrinAmt(DecimalUtils.convertFenToYuan(Double.valueOf(totalPrinAmt).longValue()));
			 prjPrdPaySch.setTotalRntAmt(DecimalUtils.convertFenToYuan(Double.valueOf(totalRntAmt).longValue()));
			 prjPrdPaySch.setTotalIntAmt(DecimalUtils.convertFenToYuan(Double.valueOf(totalIntAmt).longValue()));
			 sortPrjPrdPayList(prjPrdPayDetailList);
			 prjPrdPaySch.setPrjPrdPayDetailList(prjPrdPayDetailList);
		return prjPrdPaySch;
	}

	@Override
	public boolean modifyPrjPrdSchMPayDate(PrjPrdPaySchMVO schMVO) throws BaseException {
		return this.prjPrdPaySchMApiService.modifyPrjPrdSchMPayDate(PrjPrdPaySchMVOTransform.toDTO(schMVO));
	}

	@Override
	public List<KeyValueVO> selectSettPctList() throws BaseException {
		List<KeyValueVO> keyValueList = null;
		List<SysDictionaryDTO> dictionaryList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE__PRJ_PRD_PAY_SETT_PCT_CD);
		if (CollectionUtils.isNotEmpty(dictionaryList)) {
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}
		return keyValueList;
	}

	@Override
	public List<KeyValueVO> selectPrjPrdStatusList() throws BaseException {
		List<KeyValueVO> keyValueList = null;
		List<SysDictionaryDTO> dictionaryList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_PRD_STS_CD);
		if (CollectionUtils.isNotEmpty(dictionaryList)) {
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}
		return keyValueList;
	}

	@Override
	public boolean  modifySetPrjPrdSchMGHPayDate(Long prjPrdPayId,Date firstPayDate) throws BaseException {
		if(null==prjPrdPayId||null==firstPayDate){
			return false;
		}
		return this.prjPrdPaySchMApiService.modifySetPrjPrdSchMGHPayDate(prjPrdPayId,firstPayDate);
	}

	/** prjPrdPaySchTMApiService
	 * 风控策略结果
	 * @throws BaseException
	 */
	@Override
	public String riskControlResults(Long cstId, Long lnkCompId) throws BaseException {
		StringBuffer previewString = new StringBuffer("");
		DecimalFormat df = new DecimalFormat("######0.00");//格式化保留两位小数
		if(StringUtils.isNotEmpty(cstId)){
			Long alreadyLending = this.prjPrdPaySchTMApiService.customerAlreadyPutMoney(cstId);//客户已放款敞口金额
			Long noLending = this.prjPrdPaySchTMApiService.customerNotPutMoney(cstId);//客户已批准尚未发放敞口金额
			Long actualNctual = this.prjPrdPaySchTMApiService.selectActualNumberByCstId(cstId);//实际次数

			Double alreadyLendings = DecimalUtils.convertFenToYuan(alreadyLending);
			Double noLendings = DecimalUtils.convertFenToYuan(noLending);

			previewString.append("</br>1、【客户已放款敞口】累计金额："+df.format(alreadyLendings)+"元");
			previewString.append("</br>2、【客户已批准尚未发放敞口】累计金额："+df.format(noLendings)+"元");
			previewString.append("</br>3、【客户逾期30+ 次数】"+actualNctual+"次");
		}

		if(StringUtils.isNotEmpty(lnkCompId)){
			Long alreadyLendingGK = this.prjPrdPaySchTMApiService.affiliatedAlreadyPutMoney(lnkCompId);//挂靠公司回租业务已放款敞口金额
			Long noLendingGK = this.prjPrdPaySchTMApiService.affiliatedNotPutMoney(lnkCompId);//挂靠公司已批准尚未发放敞口金额

			Double alreadyLendingGKs = DecimalUtils.convertFenToYuan(alreadyLendingGK);
			Double noLendingGKs = DecimalUtils.convertFenToYuan(noLendingGK);

			previewString.append("</br>4、【挂靠公司回租业务已放款敞口】累计金额："+df.format(alreadyLendingGKs)+"元");
			previewString.append("</br>5、【挂靠公司已批准尚未发放敞口】累计金额："+df.format(noLendingGKs)+"元");
		}

		return previewString.toString();
	}

	/**
	 * 根据项目id查询客户保证金
	 *
	 * @param prjId
	 * @return
	 */
	@Override
	public Long searchAramtByPrjId(Long prjId) {
		return prjPrdPaySchMApiService.searchAramtByPrjId(prjId);
	}

	/**
	 * 根据项目id查询剩余本金
	 *
	 * @param prjId
	 * @return
	 * @throws BaseException
	 */
	@Override
	public Long selectRestCorpus(Long prjId) throws BaseException {
		return prjPrdPaySchMApiService.selectRestCorpus(prjId);
	}
	@Override
	public boolean modifyEntity(PrjPrdPaySchMVO schMVO) throws BaseException {
		return this.prjPrdPaySchMApiService.modifyEntity(PrjPrdPaySchMVOTransform.toDTO(schMVO));
	}
	@Override
	public DataResultVO exportPrjPrdPaySchExcelDataNew(Long id) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		String pdfName = "支付表("+DateUtils.getCurrentDateStr(DateUtils.YYYYMMDDHHMMSS)+")";
	    //String strFileName = pdfName+".xls";
	    //文件保存路径
        String filePath = PrjPrdPaySchMConstant.CODE_PAY_SCH_FILE_SAVE_PATH;
        String serverFilePath = FileUtil.getServerFilePath(filePath);
        serverFilePath = serverFilePath  + pdfName + ".xls";
        try {
        FileOutputStream   out = new FileOutputStream(serverFilePath);
        PrjPrdPaySchMVO schM = this.selectPrjPrdPaySchMAndDetailById(id);
        String lsCnNo = "";
        String cstNm = "";
        if (null != schM) {
            if (null != schM.getPrjId()) {
                PrjBscInfoVO prjBsc = this.prjBscInfoService.selectById(schM.getPrjId());
                lsCnNo = prjBsc.getLsCntNo() == null ? "" : prjBsc.getLsCntNo();
            }
            if (null != schM.getCstId()) {
                CstBscInfoVO cst = this.cstBscInfoService.selectDetailById(schM.getCstId());
                if (null != cst) {
                    cstNm = cst.getCstNm() == null ? "" : cst.getCstNm();
                }
            }
        }


        PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
        dtlQc.setPaySchId(id);
        List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(dtlQc);
        PrjPrdDtlVO dtl = null;
        double price = 0;
        double rsrvPc = 0d;
        //String machNo = "";
        String priceStr = "";
        if (CollectionUtils.isNotEmpty(dtlList)) {
            dtl = dtlList.get(0);
            if (null != dtl.getPrjPrdId()) {
                PrjPrdBscInfoVO prjPrd = this.prjPrdBscInfoService.getPrjPrdBscInfoById(dtl.getPrjPrdId());
                if (null != prjPrd) {
                    price = prjPrd.getGuidePc() == null ? 0 : prjPrd.getGuidePc();
                    rsrvPc = prjPrd.getRsrvPc() == null ? 0 : prjPrd.getRsrvPc();
                    BigDecimal bd = new BigDecimal(price);
                    priceStr = bd.toPlainString();
                }
            }
        } else {
            dtl = new PrjPrdDtlVO();
        }
        List<PrjPrdPaySchDVO> detailList = schM.getFeeDetailList();
        PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(schM.getPrjId());
        //查询日罚息率
        String punish = "";
        List<SysDictionaryDTO> list = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), prjBscInfoVO.getBuOrgCd(), CapitalConstant.CODE_CAP_OVERDUE_RATE_CD);
        if (CollectionUtils.isNotEmpty(list)) {
            punish = list.get(0).getCode();
        }

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFFont headfont = wb.createFont();
        headfont.setFontName("宋体");
        headfont.setFontHeightInPoints((short) 22);// 字体大小
        HSSFCellStyle headstyle = wb.createCellStyle();
        headstyle.setFont(headfont);
        headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
        headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
        headstyle.setLocked(true);

        HSSFSheet sheet = wb.createSheet("支付表");
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
        /*style.setBorderBottom((short)1);
        style.setBorderLeft((short)1);
        style.setBorderRight((short)1);
        style.setBorderTop((short)1);*/
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
        // 普通单元格样式（中文）
        HSSFFont font2 = wb.createFont();
        font2.setFontName("宋体");
        font2.setFontHeightInPoints((short) 12);
        style.setFont(font2);

        HSSFRow titleRow = sheet.createRow((int) 0);
        HSSFCell titleCell = titleRow.createCell(0);
        titleCell.setCellValue("支付表");
        titleCell.setCellStyle(headstyle);
        HSSFRow row = sheet.createRow((int) 1);
        HSSFCell cell = row.createCell(0);
        cell.setCellValue("支付表号");
        cell.setCellStyle(style);


        cell = row.createCell(1);
        cell.setCellValue("融资合同");
        cell.setCellStyle(style);


        cell = row.createCell(2);
        cell.setCellValue("承租人");
        cell.setCellStyle(style);


        cell = row.createCell(3);
        cell.setCellValue("租赁物总价值");
        cell.setCellStyle(style);


        cell = row.createCell(4);
        cell.setCellValue("大写");
        cell.setCellStyle(style);


        cell = row.createCell(5);
        cell.setCellValue("支付方式");
        cell.setCellStyle(style);


        HSSFRow row1 = sheet.createRow((int) 2);
        cell = row1.createCell(0);
        cell.setCellValue(schM.getPaySchNo());
        cell.setCellStyle(style);

        cell = row1.createCell(1);
        cell.setCellValue(lsCnNo);
        cell.setCellStyle(style);

        cell = row1.createCell(2);
        cell.setCellValue(cstNm);
        cell.setCellStyle(style);

        cell = row1.createCell(3);
        cell.setCellValue(schM.getTotLsItmAmt());
        cell.setCellStyle(style);

        cell = row1.createCell(4);
        cell.setCellValue(ProjectUtils.hangeToBig(schM.getTotLsItmAmt()));
        cell.setCellStyle(style);

        cell = row1.createCell(5);
        cell.setCellValue(schM.getPayWayCdNm());
        cell.setCellStyle(style);


        Integer period = ProjectUtils.getRentPeriod(schM.getLsPd().intValue(), Integer.valueOf(schM.getLsPdUntCd()));
        HSSFRow payRow = sheet.createRow((int) 3);
        HSSFCell paycell = payRow.createCell(0);
        paycell.setCellValue("租赁期数");
        paycell.setCellStyle(style);


        paycell = payRow.createCell(1);
        paycell.setCellValue("租赁周期（月）");
        paycell.setCellStyle(style);


        paycell = payRow.createCell(2);
        paycell.setCellValue("日罚息率");
        paycell.setCellStyle(style);


        paycell = payRow.createCell(3);
        paycell.setCellValue("租赁年利率");
        paycell.setCellStyle(style);


        paycell = payRow.createCell(4);
        paycell.setCellValue("利率上浮比例");
        paycell.setCellStyle(style);


        paycell = payRow.createCell(5);
        paycell.setCellValue("实际租赁物价值");
        paycell.setCellStyle(style);


        paycell = payRow.createCell(6);
        paycell.setCellValue("起租日期");
        paycell.setCellStyle(style);


        HSSFRow payRow1 = sheet.createRow((int) 4);

        paycell = payRow1.createCell(0);
        paycell.setCellValue(schM.getLsPd().intValue());
        paycell.setCellStyle(style);

        paycell = payRow1.createCell(1);
        paycell.setCellValue(period);
        paycell.setCellStyle(style);

        paycell = payRow1.createCell(2);
        paycell.setCellValue(punish + "%");
        paycell.setCellStyle(style);

        paycell = payRow1.createCell(3);
        paycell.setCellValue(schM.getAnnIntRatePct() + "%");
        paycell.setCellStyle(style);

        paycell = payRow1.createCell(4);
        paycell.setCellValue(null == schM.getIntRateRsPct() ? "" : schM.getIntRateRsPct() + "%");
        paycell.setCellStyle(style);

        paycell = payRow1.createCell(5);
        paycell.setCellValue(schM.getActLsAmt());
        paycell.setCellStyle(style);

        paycell = payRow1.createCell(6);
        paycell.setCellValue(DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD));
        paycell.setCellStyle(style);

        //产品信息
        HSSFRow prdRow = sheet.createRow((int) 5);
        HSSFCell prdcell = prdRow.createCell(0);
        prdcell.setCellValue("租赁物清单");
        prdcell.setCellStyle(style);

        prdcell = prdRow.createCell(1);
        prdcell.setCellValue("租赁物名称");
        prdcell.setCellStyle(style);
        prdcell = prdRow.createCell(2);
        prdcell.setCellValue("型号");
        prdcell.setCellStyle(style);

      /*  prdcell = row.createCell(3);
        prdcell.setCellValue("整机编号");
        prdcell.setCellStyle(style);  */

        prdcell = prdRow.createCell(3);
        prdcell.setCellValue("单价");
        prdcell.setCellStyle(style);

        prdcell = prdRow.createCell(4);
        prdcell.setCellValue("数量");
        prdcell.setCellStyle(style);
        prdcell = prdRow.createCell(5);
        prdcell.setCellValue("留购价");
        prdcell.setCellStyle(style);
        //产品信息
        HSSFRow prdValueRow = sheet.createRow((int) 6);
        HSSFCell prdValueCell = prdValueRow.createCell(0);
        prdValueCell.setCellValue(null == dtl.getPrdNm() ? "" : dtl.getPrdNm());
        prdValueCell.setCellStyle(style);

        prdValueCell = prdValueRow.createCell(1);
        prdValueCell.setCellValue(null == dtl.getPrdMdl() ? "" : dtl.getPrdMdl());
        prdValueCell.setCellStyle(style);

        prdValueCell = prdValueRow.createCell(2);
        prdValueCell.setCellValue(priceStr);
        prdValueCell.setCellStyle(style);

        prdValueCell = prdValueRow.createCell(3);
        prdValueCell.setCellValue(dtl.getPrdQty());
        prdValueCell.setCellStyle(style);

        prdValueCell = prdValueRow.createCell(4);
        prdValueCell.setCellValue(rsrvPc);
        prdValueCell.setCellStyle(style);
        //费用项列表
        HSSFRow feeRow = sheet.createRow((int) 7);
        HSSFCell feeCell = feeRow.createCell(1);
        feeCell.setCellValue("费用名称");
        feeCell.setCellStyle(style);

        feeCell = feeRow.createCell(2);
        feeCell.setCellValue("费用比例");
        feeCell.setCellStyle(style);
        feeCell = feeRow.createCell(3);
        feeCell.setCellValue("费用金额");
        feeCell.setCellStyle(style);

        feeCell = feeRow.createCell(4);
        feeCell.setCellValue("备注");
        feeCell.setCellStyle(style);
        for (int i = 0; i < schM.getFeeDetailList().size(); i++) {
            HSSFRow schRow = sheet.createRow((int) i + 8);
            PrjPrdPaySchDVO feeVo = schM.getFeeDetailList().get(i);
            schRow.createCell(1).setCellValue(null == feeVo.getFeeTypCdNm() ? "" : feeVo.getFeeTypCdNm());
            HSSFCell schCell = schRow.createCell(1);
            schCell.setCellValue(null == feeVo.getFeeTypCdNm() ? "" : feeVo.getFeeTypCdNm());
            schCell.setCellStyle(style);
            schCell = schRow.createCell(2);
            schCell.setCellValue(null == feeVo.getFeePct() ? 0 : feeVo.getFeePct());
            schCell.setCellStyle(style);
            schCell = schRow.createCell(3);
            schCell.setCellValue(null == feeVo.getFeeAmt() ? 0 : feeVo.getFeeAmt());
            schCell.setCellStyle(style);
            //保证金转出备注
            String remarkForFee = "";
            CapFeeOutLogQueryCondition condition = new CapFeeOutLogQueryCondition();
            condition.setPaySchId(feeVo.getPaySchId());
            condition.setPaySchDId(feeVo.getId());
            condition.setFeeTypCd(feeVo.getFeeTypCd());
            List<CapFeeOutLogVO> CapFeeOutLogList = this.capFeeOutLogService.searchList(condition);
            if (CollectionUtils.isNotEmpty(CapFeeOutLogList)) {
                int j = 0;
                for (CapFeeOutLogVO capFeeOutLogVO : CapFeeOutLogList) {
                    j++;
                    remarkForFee += capFeeOutLogVO.getCrtUsrNm() == null ? "" : capFeeOutLogVO.getCrtUsrNm() + "-->";
                    remarkForFee += capFeeOutLogVO.getCrtTm() == null ? "" : DateUtils.formatDateToString(capFeeOutLogVO.getCrtTm(), "yyyy-MM-dd hh:mm:ss") + "-->";
                    remarkForFee += capFeeOutLogVO.getHandleWayCdNm() == null ? "" : capFeeOutLogVO.getHandleWayCdNm();
                    remarkForFee += capFeeOutLogVO.getOutAmt() == null ? "" : BigDecimal.valueOf(capFeeOutLogVO.getOutAmt()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP) + "元-->";
                    remarkForFee += capFeeOutLogVO.getOutRem() == null ? "" : capFeeOutLogVO.getOutRem();
                    if (j < CapFeeOutLogList.size()) {
                        remarkForFee += "---";
                    }
                }
            }
            schCell = schRow.createCell(4);
            schCell.setCellValue(remarkForFee);
            schCell.setCellStyle(style);
            Region region = new Region(i + 8, (short) 4, i + 8, (short) 6);
            sheet.addMergedRegion(region);
            //schRow.createCell(2).setCellValue(null==feeVo.getFeePct()?0:feeVo.getFeePct());
            //schRow.createCell(3).setCellValue(null==feeVo.getFeeAmt()?0:feeVo.getFeeAmt());
        }
        int startRow = schM.getFeeDetailList().size() + 9;
        //费用项列表
        HSSFRow prjPayRow = sheet.createRow((int) startRow);
        HSSFCell prjPayCell = prjPayRow.createCell(0);
        prjPayCell.setCellValue("期次");
        prjPayCell.setCellStyle(style);

        prjPayCell = prjPayRow.createCell(1);
        prjPayCell.setCellValue("支付时间");
        prjPayCell.setCellStyle(style);

        prjPayCell = prjPayRow.createCell(2);
        prjPayCell.setCellValue("租金");
        prjPayCell.setCellStyle(style);

        prjPayCell = prjPayRow.createCell(3);
        prjPayCell.setCellValue("本金");
        prjPayCell.setCellStyle(style);

        prjPayCell = prjPayRow.createCell(4);
        prjPayCell.setCellValue("利息");
        prjPayCell.setCellStyle(style);

        prjPayCell = prjPayRow.createCell(5);
        prjPayCell.setCellValue("剩余本金");
        prjPayCell.setCellStyle(style);

        prjPayCell = prjPayRow.createCell(6);
        prjPayCell.setCellValue("备注");
        prjPayCell.setCellStyle(style);

        for (int i = 0; i < schM.getPrjPrdPayDetailList().size(); i++) {
            PrjPrdPrpsFeeDetailVO payVo = schM.getPrjPrdPayDetailList().get(i);
            row = sheet.createRow((int) i + startRow + 1);
            HSSFCell payCell = row.createCell(0);
            payCell.setCellValue(payVo.getPayPd());
            payCell.setCellStyle(style);

            payCell = row.createCell(1);
            payCell.setCellValue(DateUtils.formatDateToString(payVo.getPayDt(), DateUtils.YYYY_MM_DD));
            payCell.setCellStyle(style);

            payCell = row.createCell(2);
            payCell.setCellValue(payVo.getRntAmt());
            payCell.setCellStyle(style);
            //row.createCell(0).setCellValue(payVo.getPayPd());
            //row.createCell(1).setCellValue(DateUtils.formatDateToString(payVo.getPayDt(), DateUtils.YYYY_MM_DD));
            //row.createCell(2).setCellValue(payVo.getRntAmt());

            payCell = row.createCell(3);
            payCell.setCellValue(payVo.getPrinAmt());
            payCell.setCellStyle(style);

            payCell = row.createCell(4);
            payCell.setCellValue(payVo.getIntAmt());
            payCell.setCellStyle(style);

            payCell = row.createCell(5);
            payCell.setCellValue(payVo.getRemPrinAmt());
            payCell.setCellStyle(style);

            payCell = row.createCell(6);
            payCell.setCellValue("");
            payCell.setCellStyle(style);

            /*row.createCell(3).setCellValue(payVo.getPrinAmt());
            row.createCell(4).setCellValue(payVo.getIntAmt());
            row.createCell(5).setCellValue(payVo.getRemPrinAmt());
            row.createCell(6).setCellValue(""); */
        }
        int rowNum = startRow + 1 + schM.getPrjPrdPayDetailList().size();
        //费用项列表
        HSSFRow totalRow = sheet.createRow((int) rowNum);
        HSSFCell totalCell = totalRow.createCell(0);

        totalCell.setCellValue("金额合计");
        totalCell.setCellStyle(style);

        totalCell = totalRow.createCell(2);
        totalCell.setCellValue(schM.getTotalRntAmt());
        totalCell.setCellStyle(style);

        totalCell = totalRow.createCell(3);
        totalCell.setCellValue(schM.getTotalPrinAmt());
        totalCell.setCellStyle(style);

        totalCell = totalRow.createCell(4);
        totalCell.setCellValue(schM.getTotalIntAmt());
        totalCell.setCellStyle(style);

        HSSFRow cstRow1 = sheet.createRow((int) rowNum + 1);
        HSSFCell cstCell1 = cstRow1.createCell(2);
        cstCell1.setCellValue("出租人（签字）:");
        cstCell1.setCellStyle(style);

        cstCell1 = cstRow1.createCell(4);
        cstCell1.setCellValue("日期:");
        cstCell1.setCellStyle(style);

        HSSFRow cstRow2 = sheet.createRow((int) rowNum + 2);
        HSSFCell cstCell2 = cstRow2.createCell(2);
        cstCell2.setCellValue("乘租人（签字）:");
        cstCell2.setCellStyle(style);

        cstCell2 = cstRow2.createCell(4);
        cstCell2.setCellValue("日期:");
        cstCell2.setCellStyle(style);
        sheet.autoSizeColumn((short) 0); //调整第一列宽度
        sheet.autoSizeColumn((short) 1); //调整第二列宽度
        sheet.autoSizeColumn((short) 2); //调整第三列宽度
        sheet.autoSizeColumn((short) 3); //调整第四列宽度
        sheet.autoSizeColumn((short) 4); //调整第五列宽度
        sheet.autoSizeColumn((short) 5); //调整第六列宽度
        sheet.autoSizeColumn((short) 6); //调整第七列宽度
        sheet.autoSizeColumn((short) 7); //调整第八列宽度
        sheet.autoSizeColumn((short) 8); //调整第八列宽度
        sheet.autoSizeColumn((short) 9); //调整第八列宽度
        sheet.autoSizeColumn((short) 10); //调整第八列宽度
        Region region1 = new Region(0, (short) 0, 0, (short) 10);
        Region region2 = new Region(5, (short) 0, 6, (short) 0);
        sheet.addMergedRegion(region1);
        sheet.addMergedRegion(region2);
        wb.write(out);
        out.flush();
		out.close() ;
        serverFilePath = serverFilePath.replace(PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_ROOT_PATH),
                PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_SERVER_PATH));
        BaseLogUtils.info(logger, "exportPayList", "导出支付表数据,返回服务器路径.serverPath:" + serverFilePath);
        result.setData(serverFilePath);
        result.setInfo("导出成功");
        result.setSuccess(BaseConstant.IS_YESNO_YES);
    	}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "exportPrjPrdPaySch", "导出支付表失败.[paySchId="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "exportPrjPrdPaySch", "导出支付表失败.[paySchId="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
		}
		return result;
	}

	@Override
	public DataResultVO exportRentNoticeNew(Long paySchId) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if (null == paySchId) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表ID不能为空!");
		}
		String pdfName = "起租通知书("+DateUtils.getCurrentDateStr(DateUtils.YYYYMMDD)+")";
	    String strFileName = pdfName+".pdf";
	    //文件保存路径
        String filePath = PrjPrdPaySchMConstant.CODE_PAY_SCH_FILE_SAVE_PATH;
        String serverFilePath = FileUtil.getServerFilePath(filePath);
        serverFilePath = serverFilePath  + pdfName + ".pdf";
        Document document = null;
        try {
        FileOutputStream   out = new FileOutputStream(serverFilePath);

        PrjPrdPaySchMVO schM = this.selectPrjPrdPaySchMAndDetailById(paySchId);
        String lsCnNo = "";
        String cstNm = "";
        if (null != schM) {
            if (null != schM.getPrjId()) {
                PrjBscInfoVO prjBsc = this.prjBscInfoService.selectById(schM.getPrjId());
                lsCnNo = prjBsc.getLsCntNo() == null ? "" : prjBsc.getLsCntNo();
            }
            if (null != schM.getCstId()) {
                CstBscInfoVO cst = this.cstBscInfoService.selectDetailById(schM.getCstId());
                if (null != cst) {
                    cstNm = cst.getCstNm() == null ? "" : cst.getCstNm();
                }
            }
        }

            //定义Cell边框粗细   顺序是：上下左右
            float[] borderStart = {0.5f, 0.5f, 0.5f, 0};
            float[] borderRight = {0.5f, 0.5f, 0.5f, 0.5f};
            float[] borderEnd = {0.5f, 0, 0.5f, 0.5f};
            float[] borderFootRight = {0.5f, 0.5f, 0.5f, 0.5f};
            float[] borderStart1 = {0.5f, 0.5f, 0.5f, 0};
            float[] borderEnd1 = {0.5f, 0.5f, 0.5f, 0.5f};
            float[] borderStart2 = {0, 0.5f, 0.5f, 0};
            float[] borderEnd2 = {0, 0, 0, 0};
            float[] borderStart3 = {0, 0, 0, 0};
            //定义默认字体
            int[] fontDefault = {-1, -1};
            int[] fontDateDefault = new int[]{9, Font.NORMAL};
            //定义默认边距   顺序是：上下左右
            float[] paddingDefault = {3f, 3f, 2f, 2f};
            //定义默认位置    水平，垂直
            int[] alignDefault = {-1, -1};//靠左
            int[] alignCenter = {PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_CENTER};//居中
            int[] alignRight = {PdfPCell.ALIGN_RIGHT, PdfPCell.ALIGN_CENTER};//靠右
            int[] alignLift = {PdfPCell.ALIGN_LEFT, PdfPCell.ALIGN_CENTER};//靠左

            // 字体设置
            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
            Font FontColumn2 = new Font(bfChinese, 10, Font.BOLD);
            Font FontDefault22 = new Font(bfChinese, 5, Font.NORMAL);
            Font FontTitle = new Font(bfChinese, 10, Font.UNDERLINE);
            Font FontDefault2 = new Font(bfChinese, 10, Font.NORMAL);
            Font FontDefault = new Font(bfChinese, 15, Font.NORMAL);
            Font FontDefaultbig = new Font(bfChinese, 20, Font.BOLD);
            Font fa = new Font(bfChinese, 12, Font.BOLD);
            // 数字格式
            NumberFormat nfFSNum = new DecimalFormat("###########0.00");
            NumberFormat nfcFSNum = new DecimalFormat("###,###,###,##0.00");
            nfFSNum.setGroupingUsed(true);
            nfFSNum.setMaximumFractionDigits(2);
            document = new Document(PageSize.A4, 22, 22, 30, 10); // 其余4个参数，设置了页面的4个边距
            document.setMarginMirroring(true);
            PdfWriter.getInstance(document, out);
            // 打开文档
            document.open();
            PdfPCell cell = new PdfPCell();
            cell.setBorder(0);
            cell.setColspan(1);

            cell.setHorizontalAlignment(1);
            cell.setVerticalAlignment(1);
            PdfPTable tT = new PdfPTable(8);
            tT.setWidthPercentage(100f);
            tT.addCell(cell);
            tT.addCell(PdfExportServer.createCell("狮桥租赁", PdfPCell.ALIGN_LEFT, FontDefault22, 5));
            tT.addCell(PdfExportServer.createCell("起租通知书", PdfPCell.ALIGN_RIGHT, FontDefault22, 2));
            Phrase objPhase = new Phrase(" ", FontDefault);
            PdfPCell objCell = new PdfPCell(objPhase);
            objCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            objCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
            objCell.setColspan(8);
            objCell.setBorderWidthBottom(0);
            objCell.setBorderWidthLeft(0);
            objCell.setBorderWidthRight(0);
            tT.addCell(objCell);
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));

            tT.addCell(PdfExportServer.createCell("起租通知书", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));

            tT.addCell(PdfExportServer.createCell(" ", PdfPCell.ALIGN_LEFT, FontColumn2, 8));
            String lsDate = schM.getLsDt() == null ? " " : DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD);

            tT.addCell(PdfExportServer.createCell("          按照贵我双方签署的合同编号为：( " + lsCnNo + " )《设备融资租赁合同》和贵我双方签署的编号为：( ", PdfPCell.ALIGN_LEFT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell(" )《设备融资租赁合同委托采购协议》，相关设备已经贵司验收合格，起租日为 ( " + lsDate + " )", PdfPCell.ALIGN_LEFT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell("请按《租金支付表》所列的时间及金额支付租金。", PdfPCell.ALIGN_LEFT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_LEFT, FontDefault2, 8));

            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("           请贵公司予以签字盖章确认并将其中一份回执我公司，特此通知。", PdfPCell.ALIGN_LEFT, FontDefault2, 8));

            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("出租人：" + cstNm, PdfPCell.ALIGN_RIGHT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("（盖 章）                                                                                    ", PdfPCell.ALIGN_RIGHT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("       年                 月                 日                                       ", PdfPCell.ALIGN_RIGHT, FontDefault2, 8));

            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("	在此同意和确认：", PdfPCell.ALIGN_LEFT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("                                 （公 章）", PdfPCell.ALIGN_LEFT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell(" 法定代表人：                                                               （签字或盖章）                                  ", PdfPCell.ALIGN_LEFT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell(" （或委托代理人） ", PdfPCell.ALIGN_LEFT, FontDefault2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 8));
            tT.addCell(PdfExportServer.createCell("       年                 月                 日                                                                                 ", PdfPCell.ALIGN_RIGHT, FontDefault2, 8));

            document.add(tT);
            document.add(Chunk.NEXTPAGE);
            //-------------------------------第二页--------------------------------------------------------//


            PdfPTable tT4 = new PdfPTable(10);
            tT4.setWidthPercentage(100f);
            tT4.setWidthPercentage(100f);
            tT4.addCell(cell);
            tT4.addCell(PdfExportServer.createCell("狮桥租赁", PdfPCell.ALIGN_LEFT, FontDefault22, 4));
            tT4.addCell(PdfExportServer.createCell("租金支付表", PdfPCell.ALIGN_RIGHT, FontDefault22, 6));

            Phrase tObjPhase = new Phrase("  ", FontDefault2);
            PdfPCell tCell = new PdfPCell(tObjPhase);
            tCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            tCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
            tCell.setColspan(10);
            tCell.setBorderWidthBottom(0);
            tCell.setBorderWidthLeft(0);
            tCell.setBorderWidthRight(0);
            tT4.addCell(tCell);

            tT4.addCell(PdfExportServer.createCell("附件2：", PdfPCell.ALIGN_LEFT, FontDefault2, 10));
            tT4.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_LEFT, FontDefault2, 10));

            tT4.addCell(PdfExportServer.createCell("租金支付表", PdfPCell.ALIGN_CENTER, FontDefaultbig, 10));
            tT4.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 10));
            tT4.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_LEFT, FontDefault2, 10));
            tT4.addCell(PdfExportServer.createCell(bfChinese, "  ", fontDateDefault, paddingDefault, borderStart3, alignCenter, 10));


            tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁资产规模", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
            tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt() == null ? "" : schM.getTotLsItmAmt().toString(), fontDateDefault, paddingDefault, borderRight, alignCenter, 2));

            tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁年利率", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
            tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getAnnIntRatePct() == null ? "" : schM.getAnnIntRatePct().toString() + "%", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
            //查询管理费
            double mgrPct = 0d;
            double mgrAmt = 0d;
            List<PrjPrdPaySchDVO> feeList = schM.getFeeDetailList();
            for (PrjPrdPaySchDVO fee : feeList) {
                if (fee.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_MGR)) {
                    mgrPct = fee.getFeePct() == null ? 0 : Double.valueOf(fee.getFeePct());
                    mgrPct = fee.getFeeAmt() == null ? 0 : Double.valueOf(fee.getFeeAmt());
                }
            }
            tT4.addCell(PdfExportServer.createCell(bfChinese, "管理费", fontDateDefault, paddingDefault, borderStart, alignCenter, -1));
            tT4.addCell(PdfExportServer.createCell(bfChinese, mgrPct + "", fontDateDefault, paddingDefault, borderEnd, alignCenter, -1));

            tT4.addCell(PdfExportServer.createCell(bfChinese, "租金计算方式", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
            tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getPayWayCdNm(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));

            tT4.addCell(PdfExportServer.createCell(bfChinese, "租金支付期次", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
            tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsPd() == null ? "" : schM.getLsPd().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));

            tT4.addCell(PdfExportServer.createCell(bfChinese, "起租日", fontDateDefault, paddingDefault, borderStart, alignCenter, -1));
            tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsDt() == null ? "" : DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderRight, alignCenter, -1));


            tT4.addCell(PdfExportServer.createCell(bfChinese, "每期支付金额（元）", new int[]{10, Font.BOLD}, paddingDefault, borderEnd1, alignCenter, 10));
            if (schM.getPrjPrdPaySchDList().size() > 0 && schM.getPrjPrdPaySchDList() != null) {
                tT4.addCell(PdfExportServer.createCell(bfChinese, "期数", fontDefault, paddingDefault, borderStart, alignCenter, 2));
                tT4.addCell(PdfExportServer.createCell(bfChinese, "租金支付日期", fontDefault, paddingDefault, borderStart, alignCenter, 2));
                tT4.addCell(PdfExportServer.createCell(bfChinese, "每期支付租金", fontDefault, paddingDefault, borderStart, alignCenter, 2));
                tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁管理费", fontDefault, paddingDefault, borderStart, alignCenter, 2));
                tT4.addCell(PdfExportServer.createCell(bfChinese, "合计", fontDefault, paddingDefault, borderEnd, alignCenter, 2));
                //数据行
                for (int i = 0; i < schM.getPrjPrdPaySchDList().size(); i++) {
                    PrjPrdPaySchDVO pay = schM.getPrjPrdPaySchDList().get(i);
                    if (pay.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                        double total = 0d;
                        double payMgrAmt = 0d;
                        if (pay.getPayPd() == 1) {
                            total = DecimalUtils.add(pay.getFeeAmt(), mgrAmt);
                            payMgrAmt = mgrAmt;
                        } else {
                            total = pay.getFeeAmt();
                        }
                        tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getPayPd() == null ? "" : pay.getPayPd().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
                        tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getPayDt() == null ? "" : DateUtils.formatDateToString(pay.getPayDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
                        tT4.addCell(PdfExportServer.createCell(bfChinese, pay.getFeeAmt() == null ? "" : pay.getFeeAmt().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
                        tT4.addCell(PdfExportServer.createCell(bfChinese, payMgrAmt + "", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
                        tT4.addCell(PdfExportServer.createCell(bfChinese, total + "", fontDateDefault, paddingDefault, borderRight, alignCenter, 2));
                    }
                }
            }
            double totalRntAndMgr = 0d;
            totalRntAndMgr = (schM.getTotalRntAmt() == null ? 0 : schM.getTotalRntAmt()) + mgrAmt;
            tT4.addCell(PdfExportServer.createCell(bfChinese, "总计", fontDateDefault, paddingDefault, borderStart, alignCenter, 4));
            tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotalRntAmt() == null ? "" : schM.getTotalRntAmt().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
            tT4.addCell(PdfExportServer.createCell(bfChinese, mgrAmt + "", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
            tT4.addCell(PdfExportServer.createCell(bfChinese, totalRntAndMgr + "", fontDateDefault, paddingDefault, borderRight, alignCenter, 2));
            document.add(tT4);
        /*out.flush();
		out.close() ;*/
        serverFilePath = serverFilePath.replace(PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_ROOT_PATH),
                PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_SERVER_PATH));
        BaseLogUtils.info(logger, "exportPayList", "导出起租通知书数据,返回服务器路径.serverPath:" + serverFilePath);
        result.setData(serverFilePath);
        result.setInfo("导出成功");
        result.setSuccess(BaseConstant.IS_YESNO_YES);
    	}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "exportPrjPrdPaySch", "导出起租通知书失败.[paySchId="+paySchId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "exportPrjPrdPaySch", "导出起租通知书失败.[paySchId="+paySchId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
		} finally {
            try {
                document.close();
            } catch (Exception e) {
                //可能之前已经关闭过了
            }
        }
		return result;

	}

	@Override
	public DataResultVO exportFirstPayAmtNew(Long paySchId) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		 if (null == paySchId) {
	            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表ID不能为空!");
	        }
		 String pdfName = "支付表首期款明细表("+DateUtils.getCurrentDateStr(DateUtils.YYYYMMDD)+")";
		 String strFileName = pdfName+".pdf";
		 //文件保存路径
		 String filePath = PrjPrdPaySchMConstant.CODE_PAY_SCH_FILE_SAVE_PATH;
		 String serverFilePath = FileUtil.getServerFilePath(filePath);
		 serverFilePath = serverFilePath  + pdfName + ".pdf";
		 Document document = null;
		    try {
		  FileOutputStream   out = new FileOutputStream(serverFilePath);
	        PrjPrdPaySchMVO schM = this.selectPrjPrdPaySchMAndDetailById(paySchId);
	        String lsCnNo = "";
	        String cstNm = "";
	        PrjBscInfoVO prjBsc = null;
	        if (null != schM) {
	            if (null != schM.getPrjId()) {
	                prjBsc = this.prjBscInfoService.selectById(schM.getPrjId());
	                lsCnNo = prjBsc.getLsCntNo() == null ? "" : prjBsc.getLsCntNo();
	            }
	            if (null != schM.getCstId()) {
	                CstBscInfoVO cst = this.cstBscInfoService.selectDetailById(schM.getCstId());
	                if (null != cst) {
	                    cstNm = cst.getCstNm() == null ? "" : cst.getCstNm();
	                }
	            }

	                //定义Cell边框粗细   顺序是：上下左右
	                float[] borderStart = {0.5f, 0.5f, 0.5f, 0};
	                float[] borderRight = {0.5f, 0.5f, 0.5f, 0.5f};
	                float[] borderEnd = {0.5f, 0, 0.5f, 0.5f};
	                float[] borderFootRight = {0.5f, 0.5f, 0.5f, 0.5f};
	                float[] borderStart1 = {0.5f, 0.5f, 0.5f, 0};
	                float[] borderEnd1 = {0.5f, 0.5f, 0.5f, 0.5f};
	                float[] borderStart2 = {0, 0, 0.5f, 0};
	                float[] borderEnd2 = {0, 0, 0, 0};
	                float[] borderStart3 = {0, 0, 0, 0};
	                //定义默认字体
	                int[] fontDefault = {-1, -1};
	                int[] fontDateDefault = new int[]{9, Font.NORMAL};
	                //定义默认边距   顺序是：上下左右
	                float[] paddingDefault = {3f, 3f, 2f, 2f};
	                //定义默认位置    水平，垂直
	                int[] alignDefault = {-1, -1};//靠左
	                int[] alignCenter = {PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_CENTER};//居中
	                int[] alignRight = {PdfPCell.ALIGN_RIGHT, PdfPCell.ALIGN_CENTER};//靠右
	                int[] alignLift = {PdfPCell.ALIGN_LEFT, PdfPCell.ALIGN_CENTER};//靠左

	                // 字体设置
	                BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
	                Font FontColumn2 = new Font(bfChinese, 10, Font.BOLD);
	                Font FontDefault22 = new Font(bfChinese, 5, Font.NORMAL);
	                Font FontTitle = new Font(bfChinese, 10, Font.UNDERLINE);
	                Font FontDefault2 = new Font(bfChinese, 10, Font.NORMAL);
	                Font FontDefault = new Font(bfChinese, 15, Font.NORMAL);
	                Font FontDefaultbig = new Font(bfChinese, 20, Font.BOLD);
	                Font fa = new Font(bfChinese, 12, Font.BOLD);
	                // 数字格式
	                NumberFormat nfFSNum = new DecimalFormat("###########0.00");
	                NumberFormat nfcFSNum = new DecimalFormat("###,###,###,##0.00");
	                nfFSNum.setGroupingUsed(true);
	                nfFSNum.setMaximumFractionDigits(2);
	                document = new Document(PageSize.A4, 22, 22, 30, 10); // 其余4个参数，设置了页面的4个边距
	                document.setMarginMirroring(true);
	                PdfWriter.getInstance(document, out);
	                // 打开文档
	                document.open();
	                PdfPCell cell = new PdfPCell();
	                cell.setBorder(0);
	                cell.setColspan(1);

	                cell.setHorizontalAlignment(1);
	                cell.setVerticalAlignment(1);

	                PdfPTable tT4 = new PdfPTable(10);
	                tT4.setWidthPercentage(100f);
	                tT4.setWidthPercentage(100f);
	                tT4.addCell(cell);

	                tT4.addCell(PdfExportServer.createCell("支付表首期款明细表", PdfPCell.ALIGN_CENTER, FontDefaultbig, 10));
	                tT4.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_CENTER, FontColumn2, 10));
	                tT4.addCell(PdfExportServer.createCell("", PdfPCell.ALIGN_LEFT, FontDefault2, 10));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, " ", fontDateDefault, paddingDefault, borderStart3, alignCenter, 10));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "支付表号：", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getPaySchNo() == null ? "" : schM.getPaySchNo(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "融资合同：", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, lsCnNo, fontDateDefault, paddingDefault, borderStart, alignCenter, 2));


	                tT4.addCell(PdfExportServer.createCell(bfChinese, "承租人：", fontDateDefault, paddingDefault, borderStart, alignCenter, -1));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, cstNm, fontDateDefault, paddingDefault, borderRight, alignCenter, -1));

	                PdfPCell titCell = PdfExportServer.createCell(bfChinese, "租赁物清单", fontDateDefault, paddingDefault, borderStart, alignCenter, 2);
	                titCell.setRowspan(2);
	                tT4.addCell(titCell);

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物名称", fontDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "型号", fontDefault, paddingDefault, borderStart, alignCenter, -1));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "整机编号", fontDefault, paddingDefault, borderStart, alignCenter, -1));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "单价", fontDefault, paddingDefault, borderStart, alignCenter, -1));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "数量", fontDefault, paddingDefault, borderStart, alignCenter, -1));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "留购价", fontDefault, paddingDefault, borderEnd, alignCenter, 2));

	                PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
	                dtlQc.setPaySchId(paySchId);
	                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(dtlQc);
	                PrjPrdDtlVO dtl = null;
	                double price = 0d;
	                double rsrvPc = 0d;
	                // String machNo = "";
	                if (CollectionUtils.isNotEmpty(dtlList)) {
	                    dtl = dtlList.get(0);
	                    if (null != dtl.getPrjPrdId()) {
	                        PrjPrdBscInfoVO prjPrd = this.prjPrdBscInfoService.selectById(dtl.getPrjPrdId());
	                        if (null != prjPrd) {
	                            price = prjPrd.getGuidePc() == null ? 0 : prjPrd.getGuidePc();
	                            rsrvPc = prjPrd.getRsrvPc() == null ? 0 : prjPrd.getRsrvPc();
	                        }
	                    }
				 /*  if(null!=dtl.getActPrdId()){
					   //查询合格证信息
					   PrjPrdVehInfoVO veh =   this.prjPrdVehInfoService.selectById(dtl.getActPrdId());
					   if(null!=veh){
						   machNo = veh.getMachNo();
					   }
				   }*/
	                } else {
	                    dtl = new PrjPrdDtlVO();
	                }
	                List<PrjPrdPaySchDVO> detailList = schM.getFeeDetailList();
	                double depPct = 0d;//保证金比例
	                double firstPct = 0d;//首期款比例
	                double suggPct = 0d;//咨询费1比例
	                if (CollectionUtils.isNotEmpty(detailList)) {
	                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : detailList) {
	                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DEP)) {
	                            depPct = prjPrdPaySchDVO.getFeePct() == null ? 0 : prjPrdPaySchDVO.getFeePct();
	                        }
	                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_SUGG)) {
	                            suggPct = prjPrdPaySchDVO.getFeePct() == null ? 0 : prjPrdPaySchDVO.getFeePct();
	                        }
	                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DOWNPAY)) {
	                            firstPct = prjPrdPaySchDVO.getFeePct() == null ? 0 : prjPrdPaySchDVO.getFeePct();
	                        }
	                    }
	                }

	                //查询日罚息率
	                String punish = "";
	                List<SysDictionaryDTO> list = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), prjBsc.getCstMgrOrgCd(), CapitalConstant.CODE_CAP_OVERDUE_RATE_CD);
	                if (CollectionUtils.isNotEmpty(list)) {
	                    punish = list.get(0).getCode();
	                }

	                tT4.addCell(PdfExportServer.createCell(bfChinese, dtl.getPrdNm() == null ? "" : dtl.getPrdNm(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, dtl.getPrdMdl() == null ? "" : dtl.getPrdMdl(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                //   tT4.addCell(PdfExportServer.createCell(bfChinese, machNo , fontDateDefault, paddingDefault, borderStart,alignCenter, -1)) ;
	                tT4.addCell(PdfExportServer.createCell(bfChinese, price + "", fontDateDefault, paddingDefault, borderStart, alignCenter, -1));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, dtl.getPrdQty() == null ? " " : dtl.getPrdQty().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, -1));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, rsrvPc + "", fontDateDefault, paddingDefault, borderRight, alignCenter, 2));
	                //-------------------------------------------------支付表主表信息----------------------------------------------------------------------------------------//
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物总价值", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt() == null ? "" : schM.getTotLsItmAmt().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "大写", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt() == null ? "" : ProjectUtils.hangeToBig(schM.getTotLsItmAmt()), fontDateDefault, paddingDefault, borderRight, alignCenter, 3));


	                tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁物保证金比例", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, depPct + "%", fontDateDefault, paddingDefault, borderStart, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁期数", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsDt() == null ? "" : DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderRight, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "首期租金比例", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, firstPct + "%", fontDateDefault, paddingDefault, borderStart, alignCenter, 3));
	                Integer period = ProjectUtils.getRentPeriod(schM.getLsPd().intValue(), Integer.valueOf(schM.getLsPdUntCd()));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁周期（月）", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, period == null ? "" : period + "", fontDateDefault, paddingDefault, borderRight, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "咨询费1比例", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, suggPct + "%", fontDateDefault, paddingDefault, borderStart, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "日罚息率", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, punish + "%", fontDateDefault, paddingDefault, borderRight, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "利率上浮比例", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getIntRateRsPct() == null ? "" : schM.getIntRateRsPct().toString() + "%", fontDateDefault, paddingDefault, borderStart, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "租赁年利率", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getAnnIntRatePct() == null ? "" : schM.getAnnIntRatePct().toString() + "%", fontDateDefault, paddingDefault, borderRight, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "实际租赁物价值", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getTotLsItmAmt() == null ? "" : schM.getTotLsItmAmt().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "起租日期", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getLsDt() == null ? "" : DateUtils.formatDateToString(schM.getLsDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderRight, alignCenter, 3));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "支付方式 ", fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, schM.getPayWayCdNm() == null ? "" : schM.getPayWayCdNm(), fontDateDefault, paddingDefault, borderRight, alignCenter, 8));

	                if (detailList.size() > 0 && detailList != null) {
	                    tT4.addCell(PdfExportServer.createCell(bfChinese, "首期款名称", fontDefault, paddingDefault, borderStart, alignCenter, 2));
	                    tT4.addCell(PdfExportServer.createCell(bfChinese, "应收时间", fontDefault, paddingDefault, borderStart, alignCenter, 2));
	                    tT4.addCell(PdfExportServer.createCell(bfChinese, "费用金额", fontDefault, paddingDefault, borderStart, alignCenter, 2));
	                    tT4.addCell(PdfExportServer.createCell(bfChinese, "备注", fontDefault, paddingDefault, borderRight, alignCenter, 4));
	                    //数据行
	                    for (int i = 0; i < detailList.size(); i++) {
	                        PrjPrdPaySchDVO detail = detailList.get(i);
	                        if (detail.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)) {
	                            tT4.addCell(PdfExportServer.createCell(bfChinese, null==detail.getFeeTypCdNm() ? "" : detail.getFeeTypCdNm(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                            tT4.addCell(PdfExportServer.createCell(bfChinese, null==detail.getPayDt() ? "" : DateUtils.formatDateToString(detail.getPayDt(), DateUtils.YYYY_MM_DD), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                            tT4.addCell(PdfExportServer.createCell(bfChinese, null==detail.getFeeAmt() ? "" : detail.getFeeAmt().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                            tT4.addCell(PdfExportServer.createCell(bfChinese, " ", fontDateDefault, paddingDefault, borderRight, alignCenter, 4));
	                        }
	                    }
	                }
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "首期款总额", fontDateDefault, paddingDefault, borderStart, alignCenter, 4));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, null==schM.getFirstPayAmt()? "" : schM.getFirstPayAmt().toString(), fontDateDefault, paddingDefault, borderStart, alignCenter, 2));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "", fontDateDefault, paddingDefault, borderRight, alignCenter, 4));

	                tT4.addCell(PdfExportServer.createCell(bfChinese, "出租人（签字）： ", fontDefault, paddingDefault, borderStart3, alignCenter, 4));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "日期： ", fontDefault, paddingDefault, borderStart3, alignCenter, 6));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "承租人（签字）： ", fontDefault, paddingDefault, borderEnd2, alignCenter, 4));
	                tT4.addCell(PdfExportServer.createCell(bfChinese, "日期： ", fontDefault, paddingDefault, borderEnd2, alignCenter, 6));
	                document.add(tT4);
	               /* out.flush();
	                out.close() ;*/
	        serverFilePath = serverFilePath.replace(PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_ROOT_PATH),
	                PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_SERVER_PATH));
	        BaseLogUtils.info(logger, "exportPayList", "导出起租通知书数据,返回服务器路径.serverPath:" + serverFilePath);
	        result.setData(serverFilePath);
	        result.setInfo("导出成功");
	        result.setSuccess(BaseConstant.IS_YESNO_YES);
	        }
	    	}catch (BaseException ex) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(ex.getMessage());
				BaseLogUtils.info(logger, "exportPrjPrdPaySch", "导出起租通知书失败.[paySchId="+paySchId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
			}catch (Exception ex) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.error(logger, "exportPrjPrdPaySch", "导出起租通知书失败.[paySchId="+paySchId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
				BaseLogUtils.info(logger, "exportPrjPrdPaySch", "导出起租通知书失败.[paySchId="+paySchId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
			} finally {
	            try {
	                document.close();
	            } catch (Exception e) {
	                //可能之前已经关闭过了
	            }
	        }
		return result;
	}



	@Override
	public Pager searchVehDetectionListPage(Pager page) throws BaseException {
		if(null == page) page = new Pager();
		page = this.prjPrdPaySchMApiService.searchVehDetectionListPage(page,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		if (CollectionUtils.isNotEmpty(page.getResultList())) {
			List<PrjPrdPaySchMVO> prjPrdPaySchMList = PrjPrdPaySchMVOTransform.toVOList((List<PrjPrdPaySchMDTO>)page.getResultList());
			List<Long> prjIds = new ArrayList();
			List<Long> paySchIdList = new ArrayList<>();
			for(PrjPrdPaySchMVO prjPrdPay : prjPrdPaySchMList){
				prjIds.add(prjPrdPay.getPrjId());//项目ids
				paySchIdList.add(prjPrdPay.getId());//支付表ids
			}

			PrjBscInfoQueryCondition prjQc = new PrjBscInfoQueryCondition();
			prjQc.setIdList(prjIds);
			List<PrjBscInfoDTO> prjBscInfoDTOS = this.projectApiService.searchPrjBscInfoList(prjQc);

			CapPayInfoQueryCondition qc = new CapPayInfoQueryCondition();
			qc.setPaySchIdList(paySchIdList);
			List<CapPayInfoDTO> capPayInfoDTOS = this.capPayInfoApiService.searchCapPayInfoList(qc);

			List<SysOrgDTO> list = this.sysOrgApiService.searchSysOrgListBy(CurrentThreadContext.getCurrentSysCd());
			Map<String, SysOrgDTO> buOrgCdMap = new HashMap<>();
			if (CollectionUtils.isNotEmpty(list)) {
				for (SysOrgDTO sysOrgDTO : list) {
					buOrgCdMap.put(sysOrgDTO.getOrgCd(), sysOrgDTO);
				}
			}

			PrjQuatPrpsQueryCondition prjQuatQC = new PrjQuatPrpsQueryCondition();
			prjQuatQC.setPrjIds(prjIds);
			prjQuatQC.setPrpsTypCd("2");
			prjQuatQC.setIsDel(0);
			List<PrjQuatPrpsVO> quatList = this.prjQuatPrpsService.searchList(prjQuatQC);
			List<Long> prpsIdList = new ArrayList<>();//方案ids
			if(CollectionUtils.isNotEmpty(quatList)){
				for(PrjQuatPrpsVO prjqPs : quatList){
					prpsIdList.add(prjqPs.getId());
				}
			}
			PrjQuatPrpsFeeQueryCondition prjQuatPrpsFeeQc = new PrjQuatPrpsFeeQueryCondition();
			prjQuatPrpsFeeQc.setPrpsIdList(prpsIdList);
			List<PrjQuatPrpsFeeVO> feeList = this.prjQuatPrpsFeeService.searchList(prjQuatPrpsFeeQc);

			//项目类型
			Map<String,String> projectTypeList = this.sysDictionaryApiService.searchGroupToMapAll(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),DictionaryConstant.CODE_PRJ_TYPE_CD);
            //业务模式
			Map<String,String> bizTypeList = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),DictionaryConstant.CODE_PRJ_BIZ_TYP_CD);
			//付款状态
			Map<String,String> payStsCdList = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(), CapPayInfoConstant.CODE_PAY_STS_CD);

			SysOrgDTO sysOrgDTO = null;
			String orgCd = null;
			for(PrjPrdPaySchMVO vo : prjPrdPaySchMList){
				if(CollectionUtils.isNotEmpty(prjBscInfoDTOS)){
					for (PrjBscInfoDTO prjBscInfoDTO : prjBscInfoDTOS) {
						if (Objects.equals(prjBscInfoDTO.getId(), vo.getPrjId())) {
							if (projectTypeList != null && projectTypeList.containsKey(prjBscInfoDTO.getPrjTypCd())) {
								vo.setPrjTypCd(prjBscInfoDTO.getPrjTypCd());
								vo.setPrjTypCdNm(projectTypeList.get(prjBscInfoDTO.getPrjTypCd()));
							}
							if (bizTypeList != null && bizTypeList.containsKey(prjBscInfoDTO.getBizTypCd())) {
								vo.setBizTypCd(prjBscInfoDTO.getBizTypCd());
								vo.setBizTypCdNm(bizTypeList.get(prjBscInfoDTO.getBizTypCd()));
							}
							if (buOrgCdMap.containsKey(prjBscInfoDTO.getBuOrgCd())) {
								vo.setBuOrgCd(prjBscInfoDTO.getBuOrgCd());
								vo.setBuOrgCdNm(buOrgCdMap.get(prjBscInfoDTO.getBuOrgCd()).getOrgNm());
							}
							if (buOrgCdMap.containsKey(prjBscInfoDTO.getCstMgrOrgCd())) {
								sysOrgDTO = buOrgCdMap.get(prjBscInfoDTO.getCstMgrOrgCd());
								prjBscInfoDTO.setCstMgrOrgCdNm(sysOrgDTO.getOrgNm());
								orgCd = sysOrgDTO.getOrgCd();
								while(orgCd.length()>8){
									if("4".equals(sysOrgDTO.getOrgTypCd())){//分公司
										vo.setCyOrgCdNm(sysOrgDTO.getOrgNm());
									}else if("3".equals(sysOrgDTO.getOrgTypCd())){
										vo.setPrOrgCdNm(sysOrgDTO.getOrgNm());
										break;
									}
									orgCd = orgCd.substring(0,orgCd.length()-4);
									if(buOrgCdMap.containsKey(orgCd)){
										sysOrgDTO = buOrgCdMap.get(orgCd);
									}else{
										break;
									}
								}
							}
							vo.setCstNm(prjBscInfoDTO.getCstNm());
						}
					}
				}

				if(CollectionUtils.isNotEmpty(capPayInfoDTOS)){
					for(CapPayInfoDTO capPayInfoDTO : capPayInfoDTOS){
						if (Objects.equals(capPayInfoDTO.getPaySchId(), vo.getId())) {
							if (payStsCdList != null && payStsCdList.containsKey(capPayInfoDTO.getPayStsCd())) {
								vo.setPayStsCd(capPayInfoDTO.getPayStsCd());
								vo.setPayStsCdNm(payStsCdList.get(capPayInfoDTO.getPayStsCd()));
							}
						}
					}
				}

				if(CollectionUtils.isNotEmpty(quatList)){
					for(PrjQuatPrpsVO prjQuatPrpsVO : quatList){
						if (Objects.equals(prjQuatPrpsVO.getPrjId(), vo.getPrjId())) {
							if(CollectionUtils.isNotEmpty(feeList)){
								for(PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : feeList){
									if(Objects.equals(prjQuatPrpsFeeVO.getPrpsId(), prjQuatPrpsVO.getId())){
										if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_74)){
											vo.setCaijf(DecimalUtils.convertFenToYuan(prjQuatPrpsFeeVO.getFeeAmt().longValue()));
											vo.setCarPct(prjQuatPrpsFeeVO.getFeePct());
											//vo.setCarPct(DecimalUtils.round(prjQuatPrpsFeeVO.getFeePct(),10));
										}
									}
								}
							}
						}
					}
				}
			}
			page.setResultList(prjPrdPaySchMList);
		}
		return page;
	}

	@Override
	public DataResultVO addFileRec(Long prjId) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(prjId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		PrjPrdDtlQueryCondition dtlQC = new PrjPrdDtlQueryCondition();
		dtlQC.setPrjId(prjId);
		List<PrjPrdDtlVO> dtlDTOList = this.prjPrdDtlService.selectList(dtlQC);
		if (CollectionUtils.isNotEmpty(dtlDTOList)) {
			for(PrjPrdDtlVO dtlVO : dtlDTOList){
				String pdfName = dtlVO.getPaySchNo();
				//文件保存路径
				String filePath = "prjFileInfo/";
				String serverFilePath = FileUtil.getServerFilePath(filePath);
				serverFilePath = serverFilePath  + pdfName + ".xls";
				try {
					FileOutputStream out = new FileOutputStream(serverFilePath);
					PrjBscInfoVO bscInfo = this.prjBscInfoService.selectById(prjId);
					if(null==bscInfo){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601,BaseExceptionConstant.BASE_EXCEPTION_CODE_601_NAME);
					}
					CstBscInfoDTO cstBscInfoDTO = this.customerApiService.selectCstBscInfoById(bscInfo.getCstId(), bscInfo.getBuOrgCd());
					if(null==cstBscInfoDTO){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601,BaseExceptionConstant.BASE_EXCEPTION_CODE_601_NAME);
					}
					String marStsCdNm = null;
					if(cstBscInfoDTO.getCstNpBscInfoDTO() != null){
						if("1".equals(cstBscInfoDTO.getCstNpBscInfoDTO().getMarStsCd())){
							marStsCdNm="未婚";
						}
						if("3".equals(cstBscInfoDTO.getCstNpBscInfoDTO().getMarStsCd())){
							marStsCdNm="已婚";
						}
						if("2".equals(cstBscInfoDTO.getCstNpBscInfoDTO().getMarStsCd())){
							marStsCdNm="离异";
						}
						if("21".equals(cstBscInfoDTO.getCstNpBscInfoDTO().getMarStsCd())){
							marStsCdNm="初婚";
						}
						if("22".equals(cstBscInfoDTO.getCstNpBscInfoDTO().getMarStsCd())){
							marStsCdNm="再婚";
						}
						if("23".equals(cstBscInfoDTO.getCstNpBscInfoDTO().getMarStsCd())){
							marStsCdNm="复婚";
						}
						if("30".equals(cstBscInfoDTO.getCstNpBscInfoDTO().getMarStsCd())){
							marStsCdNm="丧偶";
						}
						if("90".equals(cstBscInfoDTO.getCstNpBscInfoDTO().getMarStsCd())){
							marStsCdNm="未说明的婚姻状况";
						}
					}
					List<Long> prdIds = new ArrayList<>();
					if (!prdIds.contains(dtlVO.getPrjPrdId())) {
						prdIds.add(dtlVO.getPrjPrdId());
					}
					PrjPrdBscInfoQueryCondition prdBscQc = new PrjPrdBscInfoQueryCondition();
					prdBscQc.setPrjId(Long.valueOf(prjId));
					prdBscQc.setIdList(prdIds);
					List<PrjPrdBscInfoVO> prjPrdList = this.prjPrdBscInfoService.searchList(prdBscQc);
					PrjPrdBscInfoVO prjPrdBscInfoVO = null;
					if(CollectionUtils.isNotEmpty(prjPrdList)) {
						prjPrdBscInfoVO = prjPrdList.get(0);
					}
					PrjPrdPaySchMQueryCondition mqc = new PrjPrdPaySchMQueryCondition();
					mqc.setPrjId(Long.valueOf(prjId));
					mqc.setPaySchNo(bscInfo.getLsCntNo()+"-TJ");
					mqc.setIsDel(0);
					List<PrjPrdPaySchMDTO> payMList = this.prjPrdPaySchMApiService.selectPaySchMByPaySchNo(mqc);
					DecimalFormat df = new DecimalFormat("######0.00");//格式化保留两位小数
					/*String thdPayAmt = null;
					String contAmt = null;*/
					String lsPd = null;
					if(CollectionUtils.isNotEmpty(payMList)) {
						for (PrjPrdPaySchMDTO prjPrdPaySchMDTO : payMList) {
							/*thdPayAmt = df.format(DecimalUtils.convertFenToYuan(prjPrdPaySchMDTO.getThdPayAmt()));//贷款金额(元)
							contAmt = DecimalUtils.convertFenToYuan(Double.valueOf(prjPrdPaySchMDTO.getContAmt()).longValue()).toString();//车辆净价*/
							lsPd = prjPrdPaySchMDTO.getLsPd().toString();
						}
					}
					PrjPrdPaySchMDTO prjPrdPaySchMDTO = prjPrdPaySchMApiService.selectPrjPrdPaySchMById(dtlVO.getPaySchId());
					PrjPrdPaySchDQueryCondition feeQc = new PrjPrdPaySchDQueryCondition();
					feeQc.setPaySchId(dtlVO.getPaySchId());
					feeQc.setSortName("PAY_PD");
					feeQc.setSortOrder("ASC");
					List<PrjPrdPaySchDVO> payList = this.prjPrdPaySchDService.searchList(feeQc);
					double firstTotalAmt = 0d;//首付款合计金额
					String firstTotalAmtYuan = null;
					if (CollectionUtils.isNotEmpty(payList)) {
						for (PrjPrdPaySchDVO payFee : payList) {
							if (payFee.getPayPd() == 0 && payFee.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)) {
								firstTotalAmt = DecimalUtils.add(firstTotalAmt, payFee.getFeeAmt());
								firstTotalAmtYuan = DecimalUtils.convertFenToYuan(Double.valueOf(firstTotalAmt).longValue()).toString();
							}
						}
					}
					PrjCstAccInfoQueryCondition prjCstAccQc = new PrjCstAccInfoQueryCondition();
					prjCstAccQc.setPrjId(prjId);
                    prjCstAccQc.setInsCode(bscInfo.getInsCode());
					List<PrjCstAccInfoVO> accList = this.prjCstAccInfoService.searchList(prjCstAccQc);
					PrjCstAccInfoVO prjCstAccInfoVO = null;
					if(CollectionUtils.isNotEmpty(accList)){
						prjCstAccInfoVO = accList.get(0);
					}

					Pager page = new Pager();
					PrjCstBscInfoQueryCondition qc = new PrjCstBscInfoQueryCondition();
					qc.setPrjId(Long.valueOf(prjId));
					qc.setCstRlTyp("2");
					page.setCondition(qc);
					Pager pager = this.prjCstBscInfoService.searchGuarListPage(page);
					List<PrjCstBscInfoDTO> prjList = (List<PrjCstBscInfoDTO>) pager.getResultList();
					PrjCstBscInfoDTO prjCstBscInfoDTO = null;
					if(CollectionUtils.isNotEmpty(prjList)){
						prjCstBscInfoDTO = prjList.get(0);
					}

					HSSFWorkbook wb = new HSSFWorkbook();
					HSSFFont headfont = wb.createFont();
					headfont.setFontName("等线");
					headfont.setFontHeightInPoints((short) 12);// 字体大小
					HSSFCellStyle headstyle = wb.createCellStyle();
					headstyle.setFont(headfont);
					/*headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
					headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中*/
					headstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
					headstyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
					headstyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
					headstyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
					headstyle.setLocked(true);

					HSSFSheet sheet = wb.createSheet("人保审核资料");
					HSSFCellStyle style = wb.createCellStyle();
					/*style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
					style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中*/
					style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
					style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
					style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
					style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
					// 普通单元格样式（中文）
					HSSFFont font2 = wb.createFont();
					font2.setFontName("等线");
					font2.setFontHeightInPoints((short) 12);
					style.setFont(font2);

					HSSFCellStyle qzstyle = wb.createCellStyle();
					qzstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
					qzstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
					qzstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
					qzstyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
					qzstyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
					qzstyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
					qzstyle.setFont(font2);

					HSSFRow titleRow = sheet.createRow((int) 1);
					HSSFCell titleCell = titleRow.createCell(0);
					titleCell.setCellValue("基本信息");
					titleCell.setCellStyle(headstyle);

					titleCell = titleRow.createCell(1);
					titleCell.setCellStyle(headstyle);

					titleCell = titleRow.createCell(2);
					titleCell.setCellStyle(headstyle);

					titleCell = titleRow.createCell(3);
					titleCell.setCellStyle(headstyle);

					titleCell = titleRow.createCell(4);
					titleCell.setCellStyle(headstyle);

					titleCell = titleRow.createCell(5);
					titleCell.setCellStyle(headstyle);

					HSSFRow row = sheet.createRow((int) 2);
					HSSFCell cell = row.createCell(0);
					cell.setCellValue("车辆类型");
					cell.setCellStyle(style);

					cell = row.createCell(1);
					cell.setCellValue(null != prjPrdBscInfoVO.getIsNew() ? (prjPrdBscInfoVO.getIsNew().toString().equals("1") ? "新车" : "二手车") : "");
					cell.setCellStyle(qzstyle);

					cell = row.createCell(2);
					cell.setCellValue("贷款金额(元)");
					cell.setCellStyle(style);

					cell = row.createCell(3);
					cell.setCellValue("资方融资额");
					cell.setCellStyle(qzstyle);

					cell = row.createCell(4);
					cell.setCellValue("车辆用途");
					cell.setCellStyle(style);

					cell = row.createCell(5);
					cell.setCellValue("个人贷款（多年期）");
					cell.setCellStyle(qzstyle);

					HSSFRow row1 = sheet.createRow((int) 3);
					cell = row1.createCell(0);
					cell.setCellValue("车辆名称");
					cell.setCellStyle(style);

					cell = row1.createCell(1);
					cell.setCellValue(prjPrdBscInfoVO.getBrCd());
					cell.setCellStyle(qzstyle);

					cell = row1.createCell(2);
					cell.setCellValue("车辆净价");
					cell.setCellStyle(style);

					cell = row1.createCell(3);
					cell.setCellValue(DecimalUtils.convertFenToYuan(Double.valueOf(prjPrdPaySchMDTO.getContAmt()).longValue()).toString());
					cell.setCellStyle(qzstyle);

					cell = row1.createCell(4);
					cell.setCellValue("首付金额");
					cell.setCellStyle(style);

					cell = row1.createCell(5);
					cell.setCellValue(firstTotalAmtYuan);
					cell.setCellStyle(qzstyle);

					HSSFRow row2 = sheet.createRow((int) 4);
					cell = row2.createCell(0);
					cell.setCellValue("贷款期限");
					cell.setCellStyle(style);

					cell = row2.createCell(1);
					cell.setCellValue(lsPd);
					cell.setCellStyle(qzstyle);

					cell = row2.createCell(2);
					cell.setCellValue("行驶证车主名字");
					cell.setCellStyle(style);


					cell = row2.createCell(3);
					cell.setCellValue(null != dtlVO.getLnkCompNm() ? dtlVO.getLnkCompNm() : bscInfo.getCstNm());
					cell.setCellStyle(qzstyle);

					cell = row2.createCell(4);
					cell.setCellStyle(headstyle);

					cell = row2.createCell(5);
					cell.setCellStyle(headstyle);

					HSSFRow titleRow2 = sheet.createRow((int) 5);
					HSSFCell titleCell2 = titleRow2.createCell(0);
					titleCell2.setCellValue("借款人");
					titleCell2.setCellStyle(headstyle);

					titleCell2 = titleRow2.createCell(1);
					titleCell2.setCellStyle(headstyle);

					titleCell2 = titleRow2.createCell(2);
					titleCell2.setCellStyle(headstyle);

					titleCell2 = titleRow2.createCell(3);
					titleCell2.setCellStyle(headstyle);

					titleCell2 = titleRow2.createCell(4);
					titleCell2.setCellStyle(headstyle);

					titleCell2 = titleRow2.createCell(5);
					titleCell2.setCellStyle(headstyle);

					HSSFRow jkrow = sheet.createRow((int) 6);
					HSSFCell jkcell = jkrow.createCell(0);
					jkcell.setCellValue("姓名");
					jkcell.setCellStyle(style);

					jkcell = jkrow.createCell(1);
					jkcell.setCellValue(bscInfo.getCstNm());
					jkcell.setCellStyle(qzstyle);

					jkcell = jkrow.createCell(2);
					jkcell.setCellValue("身份证号");
					jkcell.setCellStyle(style);

					jkcell = jkrow.createCell(3);
					jkcell.setCellValue(cstBscInfoDTO.getCertNo());
					jkcell.setCellStyle(qzstyle);

					jkcell = jkrow.createCell(4);
					jkcell.setCellValue("手机号");
					jkcell.setCellStyle(style);

					jkcell = jkrow.createCell(5);
					jkcell.setCellValue(null != prjCstAccInfoVO ? prjCstAccInfoVO.getMp() : "");
					jkcell.setCellStyle(qzstyle);

					HSSFRow jkrow1 = sheet.createRow((int) 7);
					jkcell = jkrow1.createCell(0);
					jkcell.setCellValue("银行卡号");
					jkcell.setCellStyle(style);

					jkcell = jkrow1.createCell(1);
					jkcell.setCellValue(null != prjCstAccInfoVO ? prjCstAccInfoVO.getAccNo() : "");
					jkcell.setCellStyle(qzstyle);

					jkcell = jkrow1.createCell(2);
					jkcell.setCellValue("婚姻状况");
					jkcell.setCellStyle(style);

					jkcell = jkrow1.createCell(3);
					jkcell.setCellValue(marStsCdNm);
					jkcell.setCellStyle(qzstyle);

					jkcell = jkrow1.createCell(4);
					jkcell.setCellValue("身份证有效期");
					jkcell.setCellStyle(style);

					jkcell = jkrow1.createCell(5);
					jkcell.setCellValue(cstBscInfoDTO.getCstNpBscInfoDTO().getCertValidEDt());
					jkcell.setCellStyle(qzstyle);

					HSSFRow jkrow2 = sheet.createRow((int) 8);
					jkcell = jkrow2.createCell(0);
					jkcell.setCellValue("工作单位");
					jkcell.setCellStyle(style);

					jkcell = jkrow2.createCell(1);
					jkcell.setCellValue(cstBscInfoDTO.getCstNpBscInfoDTO().getWorkPlc());
					jkcell.setCellStyle(qzstyle);

					jkcell = jkrow2.createCell(2);
					jkcell.setCellValue("工作地址");
					jkcell.setCellStyle(style);

					jkcell = jkrow2.createCell(3);
					jkcell.setCellValue(cstBscInfoDTO.getCstNpBscInfoDTO().getPostAddr());
					jkcell.setCellStyle(qzstyle);

					jkcell = jkrow2.createCell(4);
					jkcell.setCellStyle(headstyle);

					jkcell = jkrow2.createCell(5);
					jkcell.setCellStyle(headstyle);

					HSSFRow jkrow3 = sheet.createRow((int) 9);
					jkcell = jkrow3.createCell(0);
					jkcell.setCellValue("月收入");
					jkcell.setCellStyle(style);

					jkcell = jkrow3.createCell(1);
					jkcell.setCellValue(String.valueOf(DecimalUtils.div(DecimalUtils.convertFenToYuan(cstBscInfoDTO.getCstNpBscInfoDTO().getYrInc()), 12, 0)));
					jkcell.setCellStyle(qzstyle);

					jkcell = jkrow3.createCell(2);
					jkcell.setCellStyle(headstyle);

					jkcell = jkrow3.createCell(3);
					jkcell.setCellStyle(headstyle);

					jkcell = jkrow3.createCell(4);
					jkcell.setCellStyle(headstyle);

					jkcell = jkrow3.createCell(5);
					jkcell.setCellStyle(headstyle);

					HSSFRow titleRow3 = sheet.createRow((int) 10);
					HSSFCell titleCell3 = titleRow3.createCell(0);
					titleCell3.setCellValue("配偶信息（有则填写）");
					titleCell3.setCellStyle(headstyle);

					titleCell3 = titleRow3.createCell(1);
					titleCell3.setCellStyle(headstyle);

					titleCell3 = titleRow3.createCell(2);
					titleCell3.setCellStyle(headstyle);

					titleCell3 = titleRow3.createCell(3);
					titleCell3.setCellStyle(headstyle);

					titleCell3 = titleRow3.createCell(4);
					titleCell3.setCellStyle(headstyle);

					titleCell3 = titleRow3.createCell(5);
					titleCell3.setCellStyle(headstyle);

					HSSFRow porow = sheet.createRow((int) 11);
					HSSFCell pocell = porow.createCell(0);
					pocell.setCellValue("姓名");
					pocell.setCellStyle(style);

					pocell = porow.createCell(1);
					pocell.setCellValue(null != cstBscInfoDTO.getCstNpBscInfoDTO().getCstNpSocialRlDTO() ? cstBscInfoDTO.getCstNpBscInfoDTO().getCstNpSocialRlDTO().getRlNm() : "");
					pocell.setCellStyle(qzstyle);

					pocell = porow.createCell(2);
					pocell.setCellValue("身份证号");
					pocell.setCellStyle(style);

					pocell = porow.createCell(3);
					pocell.setCellValue(null != cstBscInfoDTO.getCstNpBscInfoDTO().getCstNpSocialRlDTO() ? cstBscInfoDTO.getCstNpBscInfoDTO().getCstNpSocialRlDTO().getCertNo() : "");
					pocell.setCellStyle(qzstyle);

					pocell = porow.createCell(4);
					pocell.setCellValue("手机号");
					pocell.setCellStyle(style);

					pocell = porow.createCell(5);
					pocell.setCellValue(null != cstBscInfoDTO.getCstNpBscInfoDTO().getCstNpSocialRlDTO() ? cstBscInfoDTO.getCstNpBscInfoDTO().getCstNpSocialRlDTO().getMp() : "");
					pocell.setCellStyle(qzstyle);

					HSSFRow titleRow4 = sheet.createRow((int) 12);
					HSSFCell titleCell4 = titleRow4.createCell(0);
					titleCell4.setCellValue("担保人信息（有则填写）");
					titleCell4.setCellStyle(headstyle);

					titleCell4 = titleRow4.createCell(1);
					titleCell4.setCellStyle(headstyle);

					titleCell4 = titleRow4.createCell(2);
					titleCell4.setCellStyle(headstyle);

					titleCell4 = titleRow4.createCell(3);
					titleCell4.setCellStyle(headstyle);

					titleCell4 = titleRow4.createCell(4);
					titleCell4.setCellStyle(headstyle);

					titleCell4 = titleRow4.createCell(5);
					titleCell4.setCellStyle(headstyle);

					HSSFRow dbrrow = sheet.createRow((int) 13);
					HSSFCell dbrcell = dbrrow.createCell(0);
					dbrcell.setCellValue("姓名");
					dbrcell.setCellStyle(style);

					dbrcell = dbrrow.createCell(1);
					dbrcell.setCellValue(null != prjCstBscInfoDTO ? prjCstBscInfoDTO.getCstNm() : "");
					dbrcell.setCellStyle(qzstyle);

					dbrcell = dbrrow.createCell(2);
					dbrcell.setCellValue("身份证号");
					dbrcell.setCellStyle(style);

					dbrcell = dbrrow.createCell(3);
					dbrcell.setCellValue(null != prjCstBscInfoDTO ? prjCstBscInfoDTO.getCertNo() : "");
					dbrcell.setCellStyle(qzstyle);

					dbrcell = dbrrow.createCell(4);
					dbrcell.setCellValue("手机号");
					dbrcell.setCellStyle(style);

					dbrcell = dbrrow.createCell(5);
					dbrcell.setCellValue(null != prjCstBscInfoDTO ? prjCstBscInfoDTO.getCstNpBscInfoDTO().getMp1() : "");
					dbrcell.setCellStyle(qzstyle);

					HSSFRow dbrrow1 = sheet.createRow((int) 14);
					HSSFCell dbrcell1 = dbrrow1.createCell(0);
					dbrcell1.setCellValue("与借款人关系");
					dbrcell1.setCellStyle(style);

					dbrcell1 = dbrrow1.createCell(1);
					dbrcell1.setCellValue(null != prjCstBscInfoDTO ? prjCstBscInfoDTO.getRlCdNm() : "");
					dbrcell1.setCellStyle(qzstyle);

					dbrcell1 = dbrrow1.createCell(2);
					dbrcell1.setCellStyle(headstyle);

					dbrcell1 = dbrrow1.createCell(3);
					dbrcell1.setCellStyle(headstyle);

					dbrcell1 = dbrrow1.createCell(4);
					dbrcell1.setCellStyle(headstyle);

					dbrcell1 = dbrrow1.createCell(5);
					dbrcell1.setCellStyle(headstyle);

					sheet.setColumnWidth(0, 6000);  //调整第一列宽度
					sheet.setColumnWidth(1, 6000);  //调整第二列宽度
					sheet.setColumnWidth(2, 6000);  //调整第三列宽度
					sheet.setColumnWidth(3, 6000);  //调整第四列宽度
					sheet.setColumnWidth(4, 6000);  //调整第五列宽度
					sheet.setColumnWidth(5, 6000);  //调整第六列宽度
					//row.setHeightInPoints(20.75f);  //设置行高

					Region region1 = new Region(0, (short) 0, 0, (short) 5);
					Region region2 = new Region(1, (short) 0, 1, (short) 5);
					Region region3 = new Region(4, (short) 3, 4, (short) 5);
					Region region4 = new Region(5, (short) 0, 5, (short) 5);
					Region region5 = new Region(8, (short) 3, 8, (short) 5);
					Region region6 = new Region(10, (short) 0, 10, (short) 5);
					Region region7 = new Region(12, (short) 0, 12, (short) 5);
					sheet.addMergedRegion(region1);
					sheet.addMergedRegion(region2);
					sheet.addMergedRegion(region3);
					sheet.addMergedRegion(region4);
					sheet.addMergedRegion(region5);
					sheet.addMergedRegion(region6);
					sheet.addMergedRegion(region7);
					wb.write(out);
					out.flush();
					out.close();
					String filePaths = serverFilePath.replace(PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_ROOT_PATH),"");
					//生成人保审核资料信息后将保存到文件上传记录表中
					List<SysUlFilesRecDTO> addList = new ArrayList<>();
					SysUlFilesRecDTO sysUlFilesRecDTO = new SysUlFilesRecDTO();
					sysUlFilesRecDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
					sysUlFilesRecDTO.setOrgCd(bscInfo.getCstMgrOrgCd());
					sysUlFilesRecDTO.setCfgCd("PRJ016");
					sysUlFilesRecDTO.setCfgDtlCd("310");
					sysUlFilesRecDTO.setPkId(bscInfo.getId().toString());
					sysUlFilesRecDTO.setTabNm("PRJ_BSC_INFO");
					sysUlFilesRecDTO.setFileNm("人保审核资料.xls");
					sysUlFilesRecDTO.setFilePath(filePaths);
					sysUlFilesRecDTO.setAbsLocPath(serverFilePath);
					sysUlFilesRecDTO.setFileRem("人保审核资料.xls");
					sysUlFilesRecDTO.setTransFlg(BaseConstant.IS_YESNO_NO);
					sysUlFilesRecDTO.setIsDel(BaseConstant.IS_YESNO_NO);
					sysUlFilesRecDTO.setCrtTm(new Date());
					sysUlFilesRecDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
					addList.add(sysUlFilesRecDTO);
					this.uploadApiService.addSysUlFilesRecListWithIsDel(addList,false);
				}catch (BaseException ex) {
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo(ex.getMessage());
					BaseLogUtils.info(logger, "addFileRec", "生成人保审核资料.[prjId="+prjId+"]"+ex.getMessage(),ex);
				}catch (Exception ex) {
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
					BaseLogUtils.error(logger, "addFileRec", "生成人保审核资料.[prjId="+prjId+"]"+ex.getMessage(),ex);
				}
			}
		}
		try{
			BaseLogUtils.info(logger,"addFileRec","=生成人保审核资料后-调用人保资料上传文件开始="+prjId);
			MessageDTO<String> peopleInsuranceFiles = this.tjBankApi.uploadPeopleInsuranceFiles(prjId);
			BaseLogUtils.info(logger,"addFileRec","=生成人保审核资料后-调用人保资料上传文件结束="+prjId+","+ JSON.toJSONString(peopleInsuranceFiles));
			if(null==peopleInsuranceFiles || !peopleInsuranceFiles.isSuccess()){
				if(StringUtils.isNotEmpty(peopleInsuranceFiles.getMessage())){
					throw new BaseException(peopleInsuranceFiles.getMessage());
				}else{
					throw new BaseException("天津-调用人保资料上传文件失败.");
				}
			}
		}catch(BaseException e){
			throw e;
		}catch(Exception e){
			BaseLogUtils.info(logger,"addFileRec","天津-调用人保资料上传文件异常=prjId:"+prjId,e);
			throw new BaseException("天津-调用人保资料上传文件异常.");
		}
		return result;
	}

	@Override
	public Long sitePaySchNoTag(PrjPrdPaySchTagVO entity) throws BaseException {
		if (null == entity) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "退换车标签记录表不能为空!");
		}
		//设置支付表标签
		Long id= prjPrdPaySchMApiService.sitePaySchNoTag(PrjPrdPaySchTagVOTransform.toDTO(entity));
		return id;
	}

	/**
	 * 查询抵扣开始期次之后的S01-S04
	 * @param paySchId
	 * @param payPd
	 * @return
	 */
	@Override
	public PrjPrdPaySchMVO searchCashDepositDeductionPaySchD(Long paySchId, Integer payPd) {
		PrjPrdPaySchMVO prjPrdPaySch = PrjPrdPaySchMVOTransform.toVO(prjPrdPaySchMApiService.searchCashDepositDeductionPaySchD(paySchId,payPd));
		return	getTotalValue(prjPrdPaySch);
	}

	@Override
	public PrjPrdPaySchMVO selectByIdWithoutDel(Long id) throws BaseException {
		if (id == null) {
			return null;
		}
		PrjPrdPaySchMDTO dto = this.prjPrdPaySchMApiService.selectByIdWithoutDel(id);
		return PrjPrdPaySchMVOTransform.toVO(dto);
	}

	@Override
	public int settleAuthority(Long paySchId) throws BaseException {

		PrjPrdPaySchMDTO paySchMDTO = prjPrdPaySchMApiService.selectPrjPrdPaySchMById(paySchId);
		if (paySchMDTO == null) {
			throw new BaseException("支付表信息不存在！");
		}
		if (paySchMDTO.getIsEnable() == BaseConstant.IS_YESNO_NO) {
			throw new BaseException("支付表非启用状态！");
		}
		if (!(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_WS.equals(paySchMDTO.getPaySchTypCd())
				|| PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_BF.equals(paySchMDTO.getPaySchTypCd()))) {
			return BaseConstant.IS_YESNO_YES;
		}

		PrjBscInfoDTO prjBscInfo = projectApiService.selectById(paySchMDTO.getPrjId());
		if (prjBscInfo == null) {
			throw new BaseException("项目基础信息不存在！");
		}
		if (!PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(prjBscInfo.getBuOrgCd())) {
			return BaseConstant.IS_YESNO_YES;
		}
		if (!(PrjBscInfoConstant.PRJ_TYP_CD_CTYW.equals(prjBscInfo.getPrjTypCd())
				|| PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(prjBscInfo.getPrjTypCd()))) {
			return BaseConstant.IS_YESNO_YES;
		}

		if (prjBscInfo.getIsInsBiz() == BaseConstant.IS_YESNO_YES) {
			return BaseConstant.IS_YESNO_YES;
		}

		PrjCstBscInfoQueryCondition qc = new PrjCstBscInfoQueryCondition();
		qc.setPrjId(paySchMDTO.getPrjId());
		List<PrjCstBscInfoVO> prjCstBscInfoVOS = prjCstBscInfoService.searchList(qc);
		if (CollectionUtils.isEmpty(prjCstBscInfoVOS)) {
			throw new BaseException("项目客户基础信息不存在！");
		}
		PrjCstBscInfoVO prjCstBscInfoVO = prjCstBscInfoVOS.get(0);
		// 自然人标识码
		String naturalPerson = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_GRP_CST_TYP_CD_NP);
		if (!naturalPerson.equals(prjCstBscInfoVO.getCstTypCd())) {
			return BaseConstant.IS_YESNO_YES;
		}
		// 当前用户的角色ID
		Long currentRoleId = CurrentThreadContext.getCurrentRoleId();
		BaseLogUtils.newLogger("支付表ID=" + paySchId + ",结清按钮权限,当前登录用户的角色ID=" + currentRoleId + ",结清专员角色ID=" + SettleConstant.SETTLE_ZY_ROLE_ID).info();
		if (SettleConstant.SETTLE_ZY_ROLE_ID.compareTo(currentRoleId) == 0) {
			// 如果是结清专员角色ID，则返回1
			return BaseConstant.IS_YESNO_YES;
		} else {
			return BaseConstant.IS_YESNO_NO;
		}
	}

}

